Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking two values onSubmit - doesn't work!

Status
Not open for further replies.

Jon99

MIS
Feb 17, 1999
23
0
0
US
I have a page where onSubmit I want this function to check if radio button 2 was selected and if there was anything entered into the mobile phone no. text area ("mobile"). What is happening at the moment is that the alert is coming up whether or not there is anything in the text area. If the function is called from the onClick on the radio button it also clears the text area (??)

Can anybody help?

function changecheck() {
if ((eval("document.form1.button[2].checked") == true)
&& (document.form1.mobile.value = ''));{
alert('You have not entered a mobile phone no.!');
return false;
}
}
 
You might want to remove the double quotes so that it
isn't evaluated as a string

"document.form1.button[2].checked"


Cheers!
Fengshui1998
 
I have removed the double quotes but the problem persists. The alert gets invoked if radio buttons two or three are clicked as well (there are three in the same group), the first button does not.

Jon
 
You might try making sure you have values for each button and checking THAT in you validation.

eg.
<input type=radio name=phoneType value=mobile>

Then checking by
document.formName.phoneType.value == &quot;mobile&quot; && ...

Hope this helps.
 
thanks - that was a kind of improvement - if I specify the value in that method clicking on the other two radio buttons doesn't invoke the function. However the alert does not come up on the button it should - javascript error &quot;valuename&quot; is not defined.

Jon
 
DO NOT check the value of a radio button! It doesn't work very reliably. You don't need the eval either, just document.forms[0].radioname[n].checked == true
make sure all the radio buttons in the set have the same name. The first is radioname[0], the second is radioname[1], etc.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top