GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack (1) Thread Tools Display Modes
  #11 (permalink)  
Old 09-28-2008
charlesh's Avatar
Master Glow Jedi
 
Join Date: Aug 2006
Location: Wichita, Kansas - better than you imagined it would be.
Posts: 152
Rep Power: 37
charlesh is on a distinguished road
Default

This works, but a bit hackish.... I first set all the vars to true and then they get changed to false as the user fills out the form. I tried the array thing, but couldn't get it to work out.

Code:
function checkForm(form){
        if (usernameerror || pworderror || emailerror || firstnameerror || lastnameerror){
          document.getElementById('form_help').innerHTML = '<img src="images/info.jpg" alt="" width="25" height="24" />&nbsp;&nbsp;Please correct any errors and re-submit.';
        return false;
         } else {
          return true;
         }
}
__________________
Charles H
http://www.harmonmediagroup.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-28-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

Quote:
Lemme guess, the site you just redid was tables and you're converting them to CSS?
LOL! That and AJAXIFY it.
Quote:
Damn. I should have charged more!
Well, we cant always expect our clients to pay for our education. You'll have good tools after this one.
Quote:
This works, but a bit hackish....
Yeah.... not a good idea....
Quote:
The problem i'm having with using one 'anyerror' var is that when an element is correct, it changes the anyerror back to true.
Hmmm..... are you sure????
anyerrors=(!ok ? true : anyerrors);
What this should do is, set anyerrors to false first then, if we get a 'false' (!ok) from the validation, we set anyerrors to true.
If the validation returns tru, then we just do a dummy operation of making anyerrors equal anyerrors.
Problem is, if your validation doesn't return anything, I think THAT is the problem. Try this instead
anyerrors=(ok==false ? true : anyerrors);
This way if you slipped and did not return an explicit true, which I will bet is the issue here, it will explicitly look for a false.
!ok is false, OR no value.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 09-28-2008
charlesh's Avatar
Master Glow Jedi
 
Join Date: Aug 2006
Location: Wichita, Kansas - better than you imagined it would be.
Posts: 152
Rep Power: 37
charlesh is on a distinguished road
Default

Jmarc,

I think I did what you mention above, just a bit backhanded way of getting there. First, I set all error vars to "true" that way, each validation function has to explicitly make them true or leave them false:

Code:
 var usernameerror=true;
    var pworderror=true;
    var emailerror=true;
    var firstnameerror=true;
    var lastnameerror=true;
By the way, I found out the hard way about variable declaration as it relates to scope in JavaScript. Weird thing is that if you declare a variable with the word 'var' inside a function, it is private. To make it global, drop the var. Strange how that works. Outside a function, variables are global. How 'bout that? Strange and bewildering.

Anyway, I'm still trying to wrap my head around your way. Give me a little more time with it... and thanks again!
__________________
Charles H
http://www.harmonmediagroup.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 09-29-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

Backhanded indeed. Not a problem if it works. But not a good idea. 10 or 20 years later (I have software from 1990s still running, so dont kid yourself!) you'll be scratching your, uhhh.... head wondering what in hell you were doing. Oh, and this is where we repeat the DOCUMENTATION mantra....
So, blitzkrieg programming? Fine, but at some point, in your leisure time, try to get it right. True is true, it is not false even if you CAN use it that way. Matt can tell you just how pleased I was when I inherited some perl code that was.... well.... with all the cursing I did over the guys code, I am sure there was an immediate karmic wave that capsized his boat somewhere.....

Yeah, var. Wouldnt it be nice if these bums would tell you what was up with that before giving examples?

However, var is a lifesaver. How clean is YOUR naming conventions? Nice to name it what you want in a function and NOT have to worry at all with what is going on with naming anywhere else.

Keep the spirit. Learning the easy way sucks. Feels nice, but...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 09-29-2008
charlesh's Avatar
Master Glow Jedi
 
Join Date: Aug 2006
Location: Wichita, Kansas - better than you imagined it would be.
Posts: 152
Rep Power: 37
charlesh is on a distinguished road
Default

Now you're making me feel guilty. OK,OK. Here's what I'm going to do -- put it on the list of clean up items for the site - it's working now, but need to come back to it. I'm back to php for the moment and trying to trouble shoot a SQL error for the lost PW script. I am a big believer in doing things right, so I want to get that right as well, just have to digest it a little further.

As far as the "shortcut" in coding for this:

Code:
 anyerrors=(!ok ? true : anyerrors);
is that the same as?:

Code:
if (anyerrors !=OK){anyerrors=true;}
Btw, John-Marc, do you work for yourself right now? Just curious...
__________________
Charles H
http://www.harmonmediagroup.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 09-30-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

Be guilty! Be VERY guilty! LOL!
As for the code, no its not the same.
Your code doesnt tell us if there were any errors.
Only if the 2 are different. So ultimately, it gives us little useful info.
First, in the spirit of doing it right we should really be doing
Code:
anyerrors=(ok==false ? true : anyerrors);
because ok could be null, which would trigger it.
That code is a one line version of an if/else, but in this version, the 'else' is required.
Long version:
Code:
if (ok==false){
 anyerrors=true;
} else {
 // Do nothing
}
Since anyerrors is a flag to tell us if there were EVER any errors in ANY of the validations, we set it false, and we loop through ALL validation to see if any come back false which is when we set it true to indicate there was an error. By maintaining your functions to return a proper true or false, you can continue to use them individually when a user changes a single value before submitting.
You could also do something like this:
Code:
anyerrors=0;
ok=...
if (ok==false)
 anyerrors++;
ok=...
if (ok==false)
 anyerrors++;
alert('# of errors: '+anyerrors)
I opted for a simple "is there or is there not any errors" because your validation seems to use dhtml nicely to indicate right on the field itself that there is one or more error.
And, yes, I am a solo act.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 10-12-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

Yo, CH!

Curious to see how things went, or did you shelve it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 10-13-2008
charlesh's Avatar
Master Glow Jedi
 
Join Date: Aug 2006
Location: Wichita, Kansas - better than you imagined it would be.
Posts: 152
Rep Power: 37
charlesh is on a distinguished road
Default

Shelved it for now - had been developing the admin console right now, but plan to go back to update the form (the good way

Thanks for the help!

Charles
__________________
Charles H
http://www.harmonmediagroup.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://glowhost.com/forums/programming-talk/ajax-forms-1441.html
Posted By For Type Date
Ajax and Forms - GlowHost Web Hosting Forums This thread Refback 09-27-2008 10:30 PM


All times are GMT -5. The time now is 08:17 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com