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

Validating Radio Buttons and text box at same time

Status
Not open for further replies.

Tread42

MIS
Feb 5, 2002
151
US
I have a form with radio buttons names "send" and values of "Mail" that has a text box for "city" and "Fax" the Fax has a text box of "send_fax" which is a texbox for the fax number. Now what I'm trying to do is validate that the user has selected either Fax or Mail and once that is determined validate the text box is not empty. Here's what I've tried to no avail. I'm pretty new to JavaScript so any help is greatly appreciated.

So for the fax validation I have:

if ((form.send.value =="Fax")) || (form.send_fax.value =="")
{
alert( "Please enter a Fax Number to send to.");
form.send_fax.focus();
return false;
}

***At this point I'm stuck as it's not validating correctly? Any thoughts/ideas?

Thank You
Regards,
Tread42
 
I'm not completely clear what you are trying to do, can you please be more specific.
Dan
 
If you post your code, we can help more.
<script>
function subForm(){
if (document.myForm.sendTo[0].checked == true){
if (document.myForm.emailAdd.value != &quot;&quot;){
document.myForm.method = &quot;post&quot;
document.myForm.action = &quot;mail.asp&quot;
document.myForm.submit()
}
}
if (document.myForm.sendTo[1].checked == true){
if (document.myForm.faxNum.value != &quot;&quot;){
document.myForm.method = &quot;post&quot;
document.myForm.action = &quot;fax.asp&quot;
document.myForm.submit()
}
}
alert (&quot;Please complete form&quot;)
}
</script>

<form name=myForm>
<input type=radio name=sendTo value=email>
<input type=radio name=sendTo value=fax>
<input name=emialAdd>
<input name=faxNum>
<input type=button value=&quot;Submit&quot; onClick=&quot;subForm()&quot;>
</form> -----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
What I'm trying to do is save if radiovalue is &quot;Fax&quot; then check to make sure &quot;send_fax&quot; is not blank and is a number. But if &quot;mail&quot; is the value check to make sure &quot;send_address&quot; is not blank. Below is some snippets of my code. I know the <TR>'s might be out of whack but that's due to the copy/paste.

Thanks for any help/suggestions.


<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
!--
function checkform ( form )
{
// ** START **
if ((form.send.value ==&quot;Fax&quot;)) || (form.send_fax.value ==&quot;&quot;)
{
alert( &quot;Please enter a Fax Number to send to.&quot;);
form.send_fax.focus();
return false;
}

// ** END **
return true ;
}
//--
</script>



<html>
<body>
<form method=&quot;POST&quot; action=&quot;/cgi-bin/formmail.pl&quot; onsubmit=&quot;return checkform(this);&quot;>
<tr>
<td width=&quot;31%&quot;>
<input type=&quot;radio&quot; value=&quot;Fax&quot; checked name=&quot;send&quot;><font face=&quot;Verdana&quot; size=&quot;2&quot;>Fax Number:</font></td>
<td width=&quot;69%&quot;><font face=&quot;Verdana&quot; size=&quot;2&quot;>
<input type=&quot;text&quot; name=&quot;send_fax&quot; size=&quot;7&quot;></font></td>
</tr>
<tr>
<td width=&quot;31%&quot;></td>
<td width=&quot;69%&quot;><font face=&quot;Verdana&quot; size=&quot;2&quot;>or</font></td>
</tr>
<tr>
<td width=&quot;31%&quot;>
<input type=&quot;radio&quot; value=&quot;Mail&quot; name=&quot;send&quot;><font face=&quot;Verdana&quot; size=&quot;2&quot;>Address:</font></td>
<td width=&quot;69%&quot;><font face=&quot;Verdana&quot; size=&quot;2&quot;>
<input type=&quot;text&quot; name=&quot;send_address&quot; size=&quot;34&quot;></font></td>
</tr>
</tr>
</body>
</html> Regards,
Tread42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top