This looks like a sequencing problem but it works the same on all the browsers I have tried (FF8, IE9, Chrome15.0.874.121, Safari4.0.5, Opera11.11).
To check the user form inputs I have an "onsubmit" that calls a JavaScript. All works well except the script can not see the value set by a set of radio buttons. Input of type Text or hidden are visible in the javascript function, but the input from set of radio buttons is "undefined". If I reduce the radio inputs to a "set" of one radio button then the value is visible in the script - if selected. In any case the action server receives the value of any selected radio button.
I have a test file striped down that shows the problem attached. - {Can't attach the file it is located at http:/ /www.knob{DOT}com/Test/pp/Test.html}
The script currently includes sever Alert boxes to troubleshoot. The commented out switch shows what I want to do if I can see the value of amount_4.
If the problem is not obvious to the casual observer, you can change line 46 to return true so the Action is called. If you change line 58 to your email address MailForm will send you an email with all the name/value pairs.
This is striped down from an "order" form including several donations and a set of 8 Membership levels. In the end it will be sent to PayPal for payment. As shown what I want to do is change the "item name" from Membership to include the membership level in addition to checking other user inputs.
JavaScript and form radio buttons
JavaScript and form radio buttons
Lou
Say what you will about Sisyphus. He always has work.
Say what you will about Sisyphus. He always has work.
Re: JavaScript and form radio buttons
Found the problem.
My answer is to add a Checked "Not now Thank you" radio button to the set. So now that I comply with the standard all is well. dah.
I did not want to have a preselected button on (like the pre checked 'sent me advertisement' box) so I did not have one of the radio buttons "on". As a result when submitted nothing was sent.W3C HTML 4.01 Specification wrote:If no radio button in a set sharing the same control name is initially "on", user agent behavior for choosing which control is initially "on" is undefined. Note. Since existing implementations handle this case differently, the current specification differs from RFC 1866 ([RFC1866] section 8.1.2.4), which states:
At all times, exactly one of the radio buttons in a set is checked. If none of the <INPUT> elements of a set of radio buttons specifies `CHECKED', then the user agent must check the first radio button of the set initially.
Since user agent behavior differs, authors should ensure that in each set of radio buttons that one is initially "on".
My answer is to add a Checked "Not now Thank you" radio button to the set. So now that I comply with the standard all is well. dah.
Lou
Say what you will about Sisyphus. He always has work.
Say what you will about Sisyphus. He always has work.
- Albert Wiersch
- Site Admin
- Posts: 3783
- Joined: Sat Dec 11, 2004 9:23 am
- Location: Near Dallas, TX
- Contact:
Re: JavaScript and form radio buttons
Hi Lou,
Thanks for posting the solution when you found it.
Would it have helped if CSE HTML Validator generated a warning for radio buttons with no default checked radio button? This sounds like a good check to add.
Thanks for posting the solution when you found it.
Would it have helped if CSE HTML Validator generated a warning for radio buttons with no default checked radio button? This sounds like a good check to add.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
Re: JavaScript and form radio buttons
Would be useful. After you ask I double checked a couple of books and none said "At all times, exactly one of the radio buttons in a set is checked." In fact the following example codeAlbert Wiersch wrote:Would it have helped if CSE HTML Validator generated a warning for radio buttons with no default checked radio button? This sounds like a good check to add.
Code: Select all
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female<br />
Lou
Say what you will about Sisyphus. He always has work.
Say what you will about Sisyphus. He always has work.