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

Radio Buttons

Status
Not open for further replies.

garfield11

IS-IT--Management
Jul 4, 2002
44
SG
Hi all,

Below are 2 radio button to display either Contact type is by phone call or thru' meeting:

<TR><TD valign=&quot;top&quot;>Contact Type ?</TD>
<TD valign=&quot;top&quot;><INPUT TYPE=&quot;radio&quot; name=&quot;ContactType&quot; value=0
<% ' Check this radio button if the existing value = 1
If edit <> -1 Then
If objRS(&quot;ContactType&quot;) = False Then
Response.Write &quot; CHECKED &quot;
End If
End If %> checked>Phone Call</OPTION>    

<INPUT TYPE=&quot;radio&quot; name=ContactType value=1
<% If edit <> -1 Then
If objRS(&quot;ContactType&quot;) = True Then
Response.Write &quot; CHECKED &quot;
End If
End If %>>Meeting</OPTION></SELECT></TD></TR>

Now, how can i make a javascript to check
- if user select &quot;Phone Call&quot; option they must fill up the phone number in the text box else an alert message will pops out?

Thanks!

Love_Garfield
 

function checkContact(f) {

if (f.ContactType[0].checked && f.phoneNumber.value==&quot;&quot;)
{
alert('You must fill in the phone number');
return false;
}

else
return true;
}

phoneNumber - is the name of text field.

Don't forget about <form> and </form> tags!
The call of checkContact() function should be like this:
<form ... onsubmit=&quot;return checkContact(this)&quot;>
 
Hi,

Thanks for replying.

Hmm... wat's f btw? document.forms[0]???

Love_Garfield
 
Yes, it's a shortcut to document.forms[0]. I pass the form object as a parameter here:
&quot;return checkContact(this)&quot;, therefore you don't need to write an actual form name.
 
Hi,

I got it!

Thanks u very much!!! =)

Love_Garfield
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top