Hanzelmans
Technical User
I'm trying to force users to provide data in one field if they answer "Yes" to a radio button in a form.
The script does display the message window correctly, however the focus is not sent back to the field that I have selected. Basically, once the user clicks the OK button in the message window it focuses on the field for a split second then submits the form.
Any suggestions?
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
while (Proceed == 1)
{
if (document.HPOne.HPMarriedOneYear[0].checked)
{
if (!document.HPOne.HPSpouseName.value)
{
Message = "Please enter the name of your spouse.";
FocusField = "HPSpouseName";
Proceed = 0;
break;
}
}
break;
}
if (Proceed == 0)
{
alert( Message );
if (FocusField != "")
{
eval("document.HPOne." + FocusField + ".focus()");
}
}
}
//-->
</script>
<CFOUTPUT>
<CENTER><span class="bmain3">Houseparent Interview</span></CENTER><br>
<CENTER>
<FORM NAME="HPOne" method="post">
<tr>
<td class="bblackfont" colspan=3>FULL-TIME HOUSEPARENT CANDIDATES
ONLY</td>
</tr>
<tr>
<td class="bblackfont">Have you been married to your current spouse
for at least one year (required for full-time position)? If
Yes,
please provide <strong>your spouse's full name</strong>.</td>
<td class="require">»</td>
<td class="nblackfont">
<input type="radio" name="HPMarriedOneYear" value="1">
Yes
<input type="radio" name="HPMarriedOneYear" value="0">
No
<input type="radio" name="HPMarriedOneYear" value="2">
N/A
<input type="text" name="HPSpouseName" maxlength="50">
</td>
</tr>
</tr>
<tr>
<td> </td>
<td> </td>
<td align=CENTER class="nblackfont"><a href="javascript:document.HPOne.reset()" onClick="myReset()"><img src="/images/form_erase.gif" height=20 width=100 border=0 alt="Erase"></a>
<input name="image" type=image onClick="ProcessForm()" src="/images/form_next.gif" alt="Next" width=100 height=20 border=0>
</td>
</tr>
</table>
</CENTER>
</form>
</CFOUTPUT>
Steve Hanzelman
Milton Hershey School
The script does display the message window correctly, however the focus is not sent back to the field that I have selected. Basically, once the user clicks the OK button in the message window it focuses on the field for a split second then submits the form.
Any suggestions?
<script language="JavaScript">
<!--
// Function to validate the form.
function ProcessForm()
{
var Proceed = 1;
var Message;
var FocusField;
while (Proceed == 1)
{
if (document.HPOne.HPMarriedOneYear[0].checked)
{
if (!document.HPOne.HPSpouseName.value)
{
Message = "Please enter the name of your spouse.";
FocusField = "HPSpouseName";
Proceed = 0;
break;
}
}
break;
}
if (Proceed == 0)
{
alert( Message );
if (FocusField != "")
{
eval("document.HPOne." + FocusField + ".focus()");
}
}
}
//-->
</script>
<CFOUTPUT>
<CENTER><span class="bmain3">Houseparent Interview</span></CENTER><br>
<CENTER>
<FORM NAME="HPOne" method="post">
<tr>
<td class="bblackfont" colspan=3>FULL-TIME HOUSEPARENT CANDIDATES
ONLY</td>
</tr>
<tr>
<td class="bblackfont">Have you been married to your current spouse
for at least one year (required for full-time position)? If
Yes,
please provide <strong>your spouse's full name</strong>.</td>
<td class="require">»</td>
<td class="nblackfont">
<input type="radio" name="HPMarriedOneYear" value="1">
Yes
<input type="radio" name="HPMarriedOneYear" value="0">
No
<input type="radio" name="HPMarriedOneYear" value="2">
N/A
<input type="text" name="HPSpouseName" maxlength="50">
</td>
</tr>
</tr>
<tr>
<td> </td>
<td> </td>
<td align=CENTER class="nblackfont"><a href="javascript:document.HPOne.reset()" onClick="myReset()"><img src="/images/form_erase.gif" height=20 width=100 border=0 alt="Erase"></a>
<input name="image" type=image onClick="ProcessForm()" src="/images/form_next.gif" alt="Next" width=100 height=20 border=0>
</td>
</tr>
</table>
</CENTER>
</form>
</CFOUTPUT>
Steve Hanzelman
Milton Hershey School