473,386 Members | 2,114 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,386 software developers and data experts.

Radio Button/Scheckbox option to validate Form

Would anyone have any suggestions/javascript code so that if one clicks
the Radio Button "Yes" below he has the option of selecting any of the
six CheckBox below. If the user clicks on Radio Button "No", he should
not have the option of clicking on any of the six checkboxes. See Code
attached. Thank you so much in advance for your help as I can't get to
make this combo work.
<p>Did you have any problems finding any of the information or
documents required to complete the Self-Registration process?<br />
<input name="InfoFindProblems" type="radio" value="yes" />
Yes
<input name="InfoFindProblems" type="radio" value="no"
onChange="disableBoxes(this.checked)" />
No</p>
<p> If yes, please indicate which (select all that apply): <br
/>

Declaration page <br />
<input name="ProblemARE" type="checkbox" id="ProblemARE"
value="1" />
Annual Rating Endorsement [A.R.E.] <br />
<input name="ProblemGrpNum" type="checkbox"
id="ProblemGrpNum" value="2" />
Group Number <br />
<input name="ProblemPolNum" type="checkbox"
id="ProblemPolNum" value="3" />
Policy Number<br />
<input name="ProblemSignDt" type="checkbox"
id="ProblemSignDt" value="4" />
Countersign Date<br />
<input name="ProblemDOCode" type="checkbox"
id="ProblemDOCode" value="5" />
District Office Code </p>

Nov 23 '05 #1
2 3444
NishSF wrote:
Would anyone have any suggestions/javascript code so that if one clicks
the Radio Button "Yes" below he has the option of selecting any of the
six CheckBox below. If the user clicks on Radio Button "No", he should
not have the option of clicking on any of the six checkboxes. See Code
attached. Thank you so much in advance for your help as I can't get to
make this combo work.
Some issues for you to think over in regard to your use of radio buttons.

1. There is some uncertainty regarding whether or not at least one radio
button should always be selected by default.

<URL:http://www.w3.org/TR/html4/interact/forms.html#radio>

I guess you should decide whether 'Yes' or 'No' should be checked by
default and ensure one of them is.

2. If you don't have one selected by default, what does neither yes nor
no mean? And once the user has selected one or the other, they can't
get back to neither selected without resetting the entire form.

3. The buttons should be enabled by default else users without script
can't access them. So what criterion should be used to disable them?
You need an onload function that makes a decision and enables/disables
them accordingly. I've used 'if yes isn't checked, disable them'.

4. If the user checks yes, then selects some checkboxes, then checks no,
should the checked boxes be unchecked? Once disabled, they won't be
sent but they will still appear checked and can't be unchecked without
answering yes, un-checking them and checking no again.

An alternative is to use a single yes/no checkbox instead of two radio
buttons - but you might think that confusing too.

Just food for thought, the final decision is of course yours. I've
given an example below using your original code with no radio button
checked by default.

My preference would be to not have the radio buttons at all, and just
have the question as:

"If you had problems ... please indicate which (select all that
apply):"
[checkbox] problem 1
[checkbox] problem 2
...

If none of the boxes are checked, the user had no problems. If some are,
they did - and no need for script at all.

<p>Did you have any problems finding any of the information or
documents required to complete the Self-Registration process?<br />
<input name="InfoFindProblems" type="radio" value="yes" />
Yes
<input name="InfoFindProblems" type="radio" value="no"
onChange="disableBoxes(this.checked)" />
onchange works differently in different browsers. According to the
specification, onchange should fire:

"...when a control loses the input focus and its value has been
modified since gaining focus"

<URL:http://www.w3.org/TR/html4/interact/scripts.html#adef-onchange>

That is what IE does. So when the user clicks on the control, nothing
happens until they click somewhere else, making it appear as if the
event is in response to the second click.

Firefox fires the event immediately (essentially as an onclick). The
usual solution is to fire the event using onclick to get consistent
behaviour.

No</p>
<p> If yes, please indicate which (select all that apply): <br
/>

Declaration page <br />
<input name="ProblemARE" type="checkbox" id="ProblemARE"
value="1" />
Annual Rating Endorsement [A.R.E.] <br />
<input name="ProblemGrpNum" type="checkbox"
id="ProblemGrpNum" value="2" />
Group Number <br />
<input name="ProblemPolNum" type="checkbox"
id="ProblemPolNum" value="3" />
Policy Number<br />
<input name="ProblemSignDt" type="checkbox"
id="ProblemSignDt" value="4" />
Countersign Date<br />
<input name="ProblemDOCode" type="checkbox"
id="ProblemDOCode" value="5" />
District Office Code </p>


Your markup indicates you may be using XHTML. In that case, modify your
script elements accordingly.

<URL:http://www.w3.org/TR/xhtml1/#h-4.8>

If you are using HTML, don't use ' />' to close empty element tags, it
is not valid HTML and potentially harmful. I've assumed you are really
using HTML:
<script type="text/javascript">

function disableBoxes()
{
var form = document.forms['formA'];
var cBoxes = ['ProblemARE', 'ProblemGrpNum', 'ProblemPolNum',
'ProblemSignDt', 'ProblemDOCode'];
var flag = !form.InfoFindProblems[0].checked;
var i = cBoxes.length;
while (i--){
form[cBoxes[i]].disabled = flag;
}
}

window.onload = disableBoxes;

</script>

<form name="formA" action="">
<p>Did you have any problems finding any of the information or
documents required to complete the Self-Registration process?<br>
<input name="InfoFindProblems" type="radio" value="yes"
onclick="disableBoxes();">Yes
<input name="InfoFindProblems" type="radio" value="no"
onclick="disableBoxes();">No</p>
<p>If yes, please indicate which (select all that apply):<br>
Declaration page<br>
<input name="ProblemARE" type="checkbox" id="ProblemARE"
value="1">Annual Rating Endorsement [A.R.E.]<br>
<input name="ProblemGrpNum" type="checkbox"
id="ProblemGrpNum" value="2">Group Number<br>
<input name="ProblemPolNum" type="checkbox"
id="ProblemPolNum" value="3">Policy Number<br>
<input name="ProblemSignDt" type="checkbox"
id="ProblemSignDt" value="4">Countersign Date<br>
<input name="ProblemDOCode" type="checkbox"
id="ProblemDOCode" value="5">District Office Code</p>
</form>


--
Rob
Nov 23 '05 #2
Rob,

Thank you so much for the detailed explanation as well as the code.

Regards,
Nish

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: trevordixon | last post by:
I have a radio button group in a form called shippinglocation. "window.form1.shippinglocation.value" returns "undefined". How do I get the value ?
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
3
by: John Davis | last post by:
I created a ASP.NET Web Form using VB.NET with a text box, 2 radio buttons. When the user click the first radio button, the text will change to uppercase. If the user clicks the other radio button,...
1
sanjay123456
by: sanjay123456 | last post by:
Dear Sir If i am working on sql.php and i am taking radio button forr option of question the i donot understand that when a user click any radio button then how i compre to answer ...
6
by: Rob | last post by:
Hi all, I would like to have a textarea control on my web page that is complete with terms and conditions, in addition, I would like a radio button beneath this to indicate the acceptance of...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
2
by: Peted | last post by:
Hi Im using c# express edition 2005 I have an MDI form, where i load multiple child forms from a dll i create, using reflection and late binding The child forms have multiple radio...
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)...
1
by: Nagababu Ch | last post by:
I have created a radio button in HTML, Using "request" object how i could accept the value of radio button in our web application.......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.