473,386 Members | 1,835 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 on when checkbox checked

I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?
<li>ABACAVIR SULFATE</li>
<INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR SULFATE"><br>
<input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ 300MG BASE">EQ 300MG BASE<br>
<input name="ABACAVIR SULFATE AMOUNT" type="radio" value="EQ 20MG BASE/ML">EQ 20MG BASE/ML<br>

Jul 20 '05 #1
1 3462
John Mullen wrote on 21 Dec 2003 at Sun, 21 Dec 2003 10:41:13 GMT:
I want to take the following HTLM and use javascript to turn on
radio buttons if checkbox is checked, can I do this with
javascript (maybe onClick or an array) or do i need a server side
script ? <li>ABACAVIR SULFATE</li>
<INPUT NAME="ingredient0" TYPE=checkbox VALUE="ABACAVIR
SULFATE"><br> <input name="ABACAVIR SULFATE AMOUNT" type="radio"
value="EQ 300MG BASE">EQ 300MG BASE<br> <input name="ABACAVIR
SULFATE AMOUNT" type="radio" value="EQ 20MG BASE/ML">EQ 20MG
BASE/ML<br>


You can do this with JavaScript, but the method differs depending on
whether you use forms to contain the controls.

With forms:

<FORM ... name="form_name">
...
<INPUT ... type="checkbox"
onclick="enableGroup('radio_name',this.form,this.c hecked)">
<INPUT ... name="radio_name" type="radio">
<INPUT ... name="radio_name" type="radio">
...
</FORM>

<SCRIPT type="text/javascript">
// Enables or disables a group of controls that share the same
// name
//
// groupName - string that contains the name of the control group
// form - the form object that contains the controls
// enable - boolean that if true, enables the group. If false,
// the group is disabled
//
function enableGroup(groupName, form, enable) {
// Get the group of radio buttons.
var group = form.elements[groupName];
var numControls = group.length;

// Loop through the collection enabling (or disabling) the
// controls.
for (var i = 0; i < numControls; ++i) {
group[i].disabled = !enable;
}
}
</SCRIPT>
With or without:

<INPUT ... type="checkbox"
onclick="enableGroup('radio_name',this.checked)">
<INPUT ... name="radio_name" type="radio">
<INPUT ... name="radio_name" type="radio">

<SCRIPT type="text/javascript">
// Enables or disables a group of controls that share the same
// name
//
// groupName - string that contains the name of the control group
// enable - boolean that if true, enables the group. If false,
// the group is disabled
//
function enableGroup(groupName, enable) {
var group = null;

// Attempt to get the group of radio buttons. First try the DOM
// approach, then try Microsoft proprietary if DOM is not
// supported.
if (document.getElementsByName) {
group = document.getElementsByName(groupName);
} else if (document.all) {
group = document.all[groupName];
}

// If the group was obtained successfully, loop through the
// collection enabling (or disabling) the controls.
if (group) {
var numControls = group.length;

for (var i = 0; i < numControls; ++i) {
group[i].disabled = !enable;
}
}
}
</SCRIPT>

The examples above can be used to enable or disable any form control,
not just radio buttons. The examples also assume that you want the
controls enabled when the checkbox is ticked. If you need them to be
disabled when the box is ticked, use this:

<INPUT ... type="checkbox"
onclick="enableGroup('radio_name',!this.checked)">

Note that an exclamation mark (!) is used here (to invert the boolean
value) and is not in the example controls above.

<snipped HTML format post>

You should only use text to post to Usenet. Please don't use HTML.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #2

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

Similar topics

3
by: shortbackandsides.no | last post by:
Here's a working code fragment out of a form. One checkbox is checked the other isn't. When you change the status of one the other changes too. <input type="checkbox" name="nlbox1" value="9"...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
3
by: Scott | last post by:
Relative newbie here, I'm looking to display the value of radio buttons and check boxes on the page before submission. So far I can do most of it. When "Hat" is checked there are to be no color...
4
by: mitch-co2 | last post by:
What I am trying to do is when someone clicks on the YES radio button I want the text field called MYTEXT to equal the text field named DATE. The below code works as long as I do NOT UN-COMMENT...
2
by: jimi_xyz | last post by:
I am creating a search engine and here is what i have so far.. <form class="complex-form" name="searchForm" method="post" action="Directory.asp"> <TABLE border="1" cellspacing="2"...
2
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there...
3
by: Ken Varn | last post by:
This is probably a simple question, but I am new to this so bear with me. I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the checkbox is checked, the 2 radio buttons are...
2
by: NishSF | last post by:
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.