Click to See Complete Forum and Search --> : Really need some check box help-Please???
krazyspur
03-11-2003, 09:36 PM
I have some Javascript code that when I pass the form to a function, all of the checkboxes become checked automatically, even if they were not checked. This happens after an alert box reminding the user to not leave info out of form. Plleeaassee, any help would be greatly, greatly appreciated. Thanks. I attached my code.
Dan Drillich
03-11-2003, 10:15 PM
if((document.rentalForm.checkPlates.checked=true) || (document.rentalForm.checkSilverware.checked=true) || (document.rentalForm.checkGlasses.checked=true))
{
if(document.rentalForm.checkPlates.checked=true) .......
Please replace all over = with == ;)
First to tell you why your checkboxes were automatically checking themselves...
In your if statements you had single ='s rather than the comparison operative, a double ==. ;)
Secondly, you may want to change a few things.
Up near the top of your script, you have this (minus your extrenous comments):
numAtt=parseInt(document.rentalForm.itemQuantity.value);
if(!(isNaN(numAtt)) && (numAtt>0) && (numAtt!=""))
It is a bit easier to use a RegExp, like this:
if (/[1-9]/.test(document.rentalForm.itemQuantity.value))I hate to say it but that whole scirpt has a lot of extrenous coding in it... :p
Oops. Didn't see that you replied, Dan. I hit post reply, and then when and did a few things. When I came back, I posted my answer...and saw that you had already anwered... :p
krazyspur
03-11-2003, 10:41 PM
Thnaks guys. Like I said, I'm still a newbie. My professor wants the isNaN statements. I am just having a hard time gripping it. You guys made it easier. Thanks, again.
Well, tell your professor... j/k. :D
krazyspur
03-12-2003, 12:21 AM
That's cool. She is a b**** sometimes. She has been programming for years, and we have a really crappy book. I'm gonna get a better reference, and, obviously, I'm using the web. I really wanted to thank you guys again. I got it working flawlessly. I cleaned it up a bunch.