...

View Full Version : HTML value for checkbox?



tdavis
10-19-2005, 05:35 PM
I know this is basic Javascript, but I just cant seem to understand. The following code is supposed to validate if at least one of the three checkboxes has been selected. But the way I am going about checking for the value is not working. What am I doing wrong? (the alerts are just for testing)

f0 = 0
f1 = 1
f2 = 2

errMsg = "The value of Pain is:"+document.pagefive.elements['Pain'].value;
alert(errMsg);

errMsg = "The value of Tingling is:"+document.pagefive.elements['Tingling'].value;
alert(errMsg);

errMsg = "The value of Numbness is:"+document.pagefive.elements['Numbness'].value;
alert(errMsg);

if ((frm.elements[f0].value =~ "Yes") &&
(frm.elements[f1].value =~ "Yes") &&
(frm.elements[f2].value =~ "Yes"))

{

Thank you!!!
-tdavis

Philip M
10-19-2005, 06:54 PM
function CheckIt(){
nc=0;
numCheck=3;
for (i=0;i<=numCheck-1;i++) {
if (document.frm.["f"+i].checked==true) {nc++}
}
if (nc==0) alert ('No boxes were checked');
}

Not sure what
if ((frm.elements[f0].value =~ "Yes") &&
(frm.elements[f1].value =~ "Yes") &&
(frm.elements[f2].value =~ "Yes"))
is supposed to do, but =~ is not valid JavaScript syntax. If it is meant to mean the string contains or includes the characters "Yes" then that is PERL.

Tony Davis
10-19-2005, 07:44 PM
Thanks! I am trying that now. I keep getting OJBECT EXPECTED error though. I see that all the time and I cant understand what exactly is missing. This language is harder than any other I've used!!!

felgall
10-19-2005, 11:00 PM
How are you calling CheckIt()? Is it being called from the onsubmit on the form tag or the onclick from an input button tag?

What are the names of the checkbox fields? Are they named f0, f1, f2?

tdavis
10-20-2005, 01:00 AM
The checkbox field names are Pain, Tingling, and Numbness. Here is my script now (see below). It seems to work, but it is not elegant. It is called with ONCLICK on an image. I just now added the frm.submit(), and I guess that gets the CGI to execute when one of the three checkboxes is clicked. I hard coded the fields because I could not figure it out otherwise.

Thanks for your help!
-tdavis


function validatePage5Form(frm)
{

var errMsg = "You did not make a selection.\nPlease choose from one of the following:\nPain, Tingling, Numbness";
var nc=0;

if (document.pagefive.elements.Pain.checked==true) {
nc++;
}

if (document.pagefive.elements.Tingling.checked==true) {
nc++;
}

if (document.pagefive.elements.Numbness.checked==true) {
nc++;
}

if (nc==0) alert(errMsg);
else frm.submit();

}

felgall
10-20-2005, 11:44 PM
Try replacing document.pagefive.elements.Pain.checked with frm.Pain.checked and similarly for the other two fields.

PhotoJoe47
10-21-2005, 12:04 AM
Thanks! I am trying that now. I keep getting OJBECT EXPECTED error though. I see that all the time and I cant understand what exactly is missing. This language is harder than any other I've used!!!

Hey Tony,

From the school of hard knocks, I have come to understand the error OJBECT EXPECTED means you made a call or used an OJBECT that was not define. I usually see this when I have called a javascript function() and I didn't quite spelled the name of the function the same as I define it. Remember case rule applies.

PhotoJoe

tdavis
10-21-2005, 01:32 AM
Thanks very much for all the help!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum