473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 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 3288
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

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

Similar topics

3
by: Owen Funkhouser | last post by:
I have a form with three radio options. And I have three buttons: <input type="submit" name="mainform_action" value="Edit Data"> <input type="submit" name="mainform_action" value="View Data">...
2
by: Stoic | last post by:
I'm offering a selection of three items. One is $25, the second is $50, the third is $100. Along with selection one of the items I need to pass the quantity of the selection. Here is the code now....
6
by: Paul | last post by:
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side...
5
by: swatidesai0407 | last post by:
hi im validating radio buttons i create dis radio button in php based on some how many records of my query. i wrote a javascript to validate this buttons. wat i do is dat wen no radio button...
8
by: photoboy | last post by:
I have racked by brain long enough on this, so now I need the help of someone who knows what they are doing. Here is what I am trying to achieve: First, I have two radio buttons (both unchecked)...
10
by: mukeshrasm | last post by:
Hi I have a html in which there is two selection box and two radio button. Radio buttion is of array type. What I want if user will click the radio button then only he/she be able to make...
4
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.