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

Need suggestions for a validation script

Status
Not open for further replies.

nalbiso

Programmer
Aug 31, 2000
71
US
Hi!

I have a form with two radio buttons with the group name of status. The value of one of the buttons is "In Office" the other button's value is "Out of Office". I also have a textbox called destination. I am looking for suggestions for a script cause an alert box to appear when the "Out of Office" radio button is checked and the textbox called destination is not filled out. I tried to figure this out in javascript, but I am totally off base.

Thanks for any help!

 
Check to see which radio button is checked, then set a variable for destination.value. Check to see if the variable has data, if not, pop-up an alert.

//after checking radio button
Dest = document.FormGroupName.Destination.value;

//add alert if name is blank
if (Dest == ""){
alert('You must enter a destination.');

Hope that helps,
Joli
 
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
<script language=&quot;javascript&quot;>
function check(){
if (document.rad.status[1].checked && document.rad.where.value==&quot;&quot;)
alert(&quot;You forgot something! Don't you think?&quot;);
return false;
}
</script>
</HEAD>
<BODY>

<form name=&quot;rad&quot; onsubmit=&quot;return check();&quot;>

In Office: <input type=&quot;radio&quot; name=&quot;status&quot; value=&quot;in&quot; checked><br>

Out of Office: <input type=&quot;radio&quot; name=&quot;status&quot; value=&quot;out&quot;>&nbsp;Where: <input type=&quot;text&quot; name=&quot;where&quot;><br>

<input type=&quot;submit&quot;>
</form>

</BODY>
</HTML>
 
Thanks, I modified it to fit my field, radio buttons and form names, but I keep getting an &quot;object expected&quot; error. I tried running your script exactly as you typed it here in notepad to test it out and I got the same error.

Here was my page code:

<SCRIPT LANGUAGE=&quot;Javascript&quot;>
function check(){
if (document.form1.status.[1].checked && document.form1.destination.value==&quot;&quot;)
alert(&quot;You must indicate your destination when posting an Out of Office Record&quot;);
return false;
}
</SCRIPT>

<form Name=&quot;form1&quot; METHOD=&quot;POST&quot; ACTION=&quot;EBoard2.asp&quot; onsubmit=&quot;return check();&quot;>
<tr>
<td width=&quot;207&quot;><font face=&quot;Tahoma&quot;>In office<input type=&quot;radio&quot; value=&quot;In Office&quot; checked name=&quot;Status&quot;>
Out of Office<input type=&quot;radio&quot; name=&quot;Status&quot; value=&quot;Out of Office&quot;></font></td>
</tr>
<tr>
<TEXTAREA rows=&quot;1&quot; cols=&quot;20&quot; NAME=&quot;Destination&quot; size=&quot;20&quot;></TEXTAREA></font></td>
</tr>

Did I miss something?

Thanks for your help!
 
The error is the dot in this statement in function(I've made it [red]red[/red] and underlined to make it stand out):


if (document.form1.status[red].[/red][1].checked &&
_ _

Should be :

if (document.form1.status[1].checked && _ _ _

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top