OZONE Asylum
Forums
DHTML/Javascript
Form with one of two radio buttons required
This page's ID:
29740
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hi My my.. this is what it looks like in this subforum.. Haven't been here for years. Anyhow, I'm working on an order form sent through JMail, and I'm stuck on validating radio buttons. All fields in the form are supposed to be mandatory, and I have been able to get the Javascript to validate all fields apart from the radio buttons. Basicly I have 2 unchecked buttons (different payment methods) in the same array in the form [code] <input type="radio" name="payment" Value="PF" >PF <input type="radio" name="payment" Value="BG">BG [/code] The script I'm using to validate the rest looks like: [code] <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function verify() { var themessage = "Please fill in the following fields "; if (document.form.firstname.value=="") { themessage = themessage + " - Förnamn"; } if (document.form.lastname.value=="") { themessage = themessage + " - Efternamn"; } if (document.form.adress.value=="") { themessage = themessage + " - Adress"; } if (document.form.zip.value=="") { themessage = themessage + " - Postnummer"; } if (document.form.city.value=="") { themessage = themessage + " - Ort"; } if (document.form.email.value=="") { themessage = themessage + " - E-mail"; } if (document.form.phone.value=="") { themessage = themessage + " - Telefonnummer"; } if (document.form.approve.checked==false) { themessage = themessage + " - Godkännande"; } //alert if fields are empty and cancel form submit if (themessage == "Please fill in the following fields ") { document.form.submit(); } else { alert(themessage); return false; } } // End --> </script> [/code] but I don't know how to check that one of the two radio buttons is checked. I could go for the easy solution and have one pre-checked, but I'd prefer to have them both unchecked. I did try adding something like: [code] } if (document.form.payment.checked==false) { themessage = themessage + " - Betalning"; } [/code] which naturally didn't work as one of the buttons will false at all times. The problem is that I can't really write javascript from scratch, but just manipulate and tweak scripts I find.. Is there an easy solution to this? I have googled quite a but but I guess I'm asking the wrong questions cause the results I get is not really helping (most are too complex or dealing with the vaules of the buttons rather than the true/false problem) Thanks
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »