/    Sign up×
Community /Pin to ProfileBookmark

Radio object onchange require text entry?

Hi, I need help with a form.
I have a rather long form that already has an onsubmit function to check for required fields. But now my client wants something I’m not sure how to do.
We have 4 radio buttons. If either of 2 of them are checked, my client wants to require that a text field is filled out.

The form part is:

[code=html]<table border=”0″ cellpadding=”2″ style=”border-collapse: collapse” id=”table3″ cellspacing=”2″ width=”100%”>
<tr>
<td align=”center”>
<p align=”left”><b>Shipped</b></td>
<td align=”center” width=”393″>
<p align=”left”><b>E-Mailed</b></td>
</tr>
<tr>
<td>
<input type=”radio” name=”Fee” value=”$150.00 1 Loan – Shipping Documents” tabindex=”28″>1
Loan $150.00</td>
<td width=”393″>
<input type=”radio” name=”Fee” value=”$200.00- 1 Loan by Email” tabindex=”30″>1
Loan $200.00</td>
</tr>
<tr>
<td>
<input type=”radio” name=”Fee” value=”$225.00 – 2 Loans- Shipping Documents” tabindex=”29″>2
Loans (1st &amp; 2nd) $225.00</td>
<td width=”393″>
<input type=”radio” name=”Fee” value=”$300.00 – 2 Loans by Email” tabindex=”31″>2
Loans (1st &amp; 2nd) $300.00</td>
</tr>
<tr>
<td>
<b>Return Documents to Address:<font color=”#FF0000″><br>
(Required for E-mailed Docs)</font></b></td>
<td width=”393″>
<textarea name=”Return_Docs_Address” rows=”3″ cols=”29″ tabindex=”32″ wrap=”virtual” onblur=”Substitute();”></textarea></td>
</tr>
<tr>
<td>
<font color=”#FF0000″><b>Return via</b></font></td>
<td width=”393″>
<input type=”radio” name=”Return_Via” value=”FedEx” tabindex=”33″ checked>Fed
Ex
<input type=”radio” name=”Return_Via” value=”UPS” tabindex=”34″>UPS </td>
</tr>
<tr>
<td>
<font color=”#FF0000″><b>FedEx/UPS Account #</b></font></td>
<td width=”393″>
<strong>
<input type=”text” size=”33″ maxlength=”256″ name=”Shipping_Account_No” tabindex=”35″></strong></td>
</tr>
</table>[/code]

If the radio “Fee” is checked for either of the Email options ($300.00 – 2 Loans by Email, or $200.00- 1 Loan by Email). Then he wants the “Return_Docs_Address” and “Shipping_Account_No” required.

Any ideas??
Thanks for any help you can give.
Robyn

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJun 30.2005 — Something on the lines of this example maybe

[code=php]<script type="text/javascript">
<!--
function test(){

if(document.myform.Fee[1].checked||document.myform.Fee[3].checked){

if(document.myform.Return_Docs_Address.value==""){
alert("Please enter the Return address")
}

if(document.myform.Shipping_Account_No.value==""){
alert("Please enter the Shipping Account Number")
}

}

}

//-->
</script>

<form name="myform">


<table border="0" cellpadding="2" style="border-collapse: collapse" id="table3" cellspacing="2" width="100%">
<tr>
<td align="center"><p align="left"><b>Shipped</b></td>
<td align="center" width="393"><p align="left"><b>E-Mailed</b></td>
</tr>
<tr>
<td><input type="radio" name="Fee" value="$150.00 1 Loan - Shipping Documents" tabindex="28">1 Loan $150.00</td>
<td width="393"><input type="radio" name="Fee" value="$200.00- 1 Loan by Email" tabindex="30">1 Loan $200.00</td>
</tr>
<tr>
<td><input type="radio" name="Fee" value="$225.00 - 2 Loans- Shipping Documents" tabindex="29">2 Loans (1st &amp; 2nd) $225.00</td>
<td width="393"><input type="radio" name="Fee" value="$300.00 - 2 Loans by Email" tabindex="31">2 Loans (1st &amp; 2nd) $300.00</td>
</tr>
<tr>
<td><b>Return Documents to Address:<font color="#FF0000"><br>
(Required for E-mailed Docs)</font></b></td>
<td width="393"><textarea name="Return_Docs_Address" rows="3" cols="29" tabindex="32" wrap="virtual" onblur="Substitute();"></textarea></td>
</tr>
<tr>
<td><font color="#FF0000"><b>Return via</b></font></td>
<td width="393"><input type="radio" name="Return_Via" value="FedEx" tabindex="33" checked>Fed Ex
<input type="radio" name="Return_Via" value="UPS" tabindex="34">UPS </td>
</tr>
<tr>
<td><font color="#FF0000"><b>FedEx/UPS Account #</b></font></td>
<td width="393"><strong><input type="text" size="33" maxlength="256" name="Shipping_Account_No" tabindex="35"></strong></td>
</tr>
</table>



<input type="button" value="Button" onclick="test()">
</form>[/code]
Copy linkTweet thisAlerts:
@rlegrisauthorJun 30.2005 — I'll give it a try! Thank you so much for taking the time to respond!! ?

Robyn
×

Success!

Help @rlegris spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...