471,066 Members | 1,176 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Field validation based on radio button selection

I'm trying to develop an order page and in one section, the customer specifies a shipment type using radio buttons that is submitted to the shopping cart. There are 4 buttons. If either of the first two are selected, the form should submit the data. If either of the last two are selected, I want the form to require input on a text field to collect an account number (op40_LabelShip). I have gotten the form to require the field, but it requires it no matter which radio button is checked. Also, although the field is required, the form submits the other data anyway. I'm stuck at this point. Any help would be appreciated. Here's what I have:



[HTML]<script language="JavaScript" type="text/JavaScript"><!--

function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function formvalidation(thisform)
{
with (thisform)
{
if (emptyvalidation(op40_LabelShip,"For overnight FedEx/DHL shipping, you must enter an account numnber.")==false) {op40_LabelShip.focus(); return false;};
}
}

//--></script>


<form name="form" onsubmit="formvalidation(this);" action="http://www.xyz/cart.cgi" method="post">

<input value="s-9999^=SF==NA=^***Mailing Label Standard Shipping^0.00^1^^^N/A^^"
type="radio" id="ShipStd" name="item_LabelShip" checked="checked"
onclick="javascript:document.form.ShipperAcctNumbe r.disabled=true" />
Standard USPS Delivery For Label Order - No Charge<br />

<input value="s-9999^=SF==NA=^***Bill Express Shipping To Credit Card Used For This Order^0.00^1^^^N/A^^"
type="radio" id="CCShip" name="item_LabelShip"
onclick="javascript:document.form.ShipperAcctNumbe r.disabled=true" />
Bill Label Order Express Shipping To Credit Card Used For This Order<br />

<input value="s-9999^=SF==NA=^***Bill Express Label Order Shipping to FedEx Acct # ^0.00^1^^^N/A^^"
type="radio" id="ExpressShip" name="item_LabelShip"
onclick="javascript:document.form.ShipperAcctNumbe r.disabled=false" />
FedEx Shipping (must specify account number below)<br />

<input value="s-9999^=SF==NA=^***Bill Express Label Order Shipping to DHL Acct # ^0.00^1^^^N/A^^"
type="radio" id="ExpressShip" name="item_LabelShip"
onclick="javascript:document.form.ShipperAcctNumbe r.disabled=false" />
DHL Shipping (must specify account number below)<br />





FedEx/DHL Account Number:<input class="text" id="ShipperAcctNumber" size="15" name="op40_LabelShip" /></p>
<input type="hidden" value="s-9999^=SF==NA=^(op40_LabelShip)^0.00^1^^^N/A^^" /><p align="left"></p>
<hr />


<input type="image" src="../../UploadedImages/ShoppingCartButtons/addtocart.gif" value="Submit" border="0" name="add" />[/HTML]
Apr 26 '07 #1
1 3094
acoder
16,027 Expert Mod 8TB
document.getElementsByName("item_LabelShip") should give you the radio buttons. Loop over them and check the checked property of each to get the selected radio button.
Jan 30 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Owen Funkhouser | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.