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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Buttons on a Form

Status
Not open for further replies.

crmayer

Programmer
Nov 22, 2002
280
US
I have a yes and no radio button on a application form and if a user checks "Yes", then I want to make then fill in the explanation field. I am trying to verify onsubmit if the radio button "Yes" is checked, then show message and set focus on explain, but it does not seem to do this. I am using Frontpage to validate these fields.

if(theForm.license_denied[0].checked)
{
alert("You must give explaination");
theForm.A_explain.focus();
return (false);
}
this in inside my validation function that checks all my required fields on the form. I am not even getting in to this if statement. What am I doing wrong???
 
The code you posted looks fine to me.

So the problem must be elsewhere.

Your code implies that the first radio button named license_denied is the Yes button. Is that true?

Either your form is named theForm, or your validation function is called with an argument named theForm that points to the form. Is that true?

Have you confirmed that the validation function is being called? You can do that by putting an alert as the first statement. And get some more information by displaying the value you are testing.

function isValid(theForm){
alert("Inside: " + theForm.license_denied[0].checked );
}

Are you calling the validation function like this?

<form . . . onsubmit=&quot;return isValid(this);&quot;>

 
May be try another way
<form . . . onsubmit=&quot;return isValid();&quot;>
<input type=radio name=license_denied onClick=&quot;please_give_explaination();&quot;>
<input type=radio name=license_denied value=&quot;No&quot;>
<input type=text name=explaination value=&quot;&quot; onClick=&quot;theForm.explaination.disabled = true;&quot; disabled>

...

<script>
function please_give_explaination(){
if (theForm.explaination.disabled) {
alert(&quot;You must give explaination&quot;);
theForm.explaination.disabled = false;
theForm.explaination.focus();
}
}
function isValid(){
if (!theForm.explaination.disabled)
if (!theForm.explaination.value.length){
alert(&quot;You must give explaination&quot;);
return false;
}
}

================================
Sincerely,
Vlad Smachny
AlarIT programmer
================================
 
Thank you. The validation was not getting called. The weird thing is that I can not see the javascript when I open the html code in Frontpage, if I close the file and open the html code in notepad, there it is. I don't understand why the javacript function is not being displayed in Frontpage, but I got it.

Thanks for the help. The code was right, I just had to find where Frontpage was hiding the function.
 
I've heard Frontpage does that if you copy and paste Javascript into the editor. If you paste it first into Notepad, and then copy that and post it into Frontpage, it works apparently. Can't tell for sure though, because I don't use it. Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top