473,396 Members | 1,827 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,396 software developers and data experts.

Autoselect in a radio

I have combination of radio and select/input:
http://sneleopard.dk/radio.html

Is there a javascript which automatically sets radio 1, when the user
does something with field 1, and automatically sets radio 2, when the
user does something with field 2?

Sep 5 '05 #1
11 4140
hygum wrote:
I have combination of radio and select/input:
http://sneleopard.dk/radio.html

Is there a javascript which automatically sets radio 1, when the user
does something with field 1, and automatically sets radio 2, when the
user does something with field 2?


Yes, but it a question like: "Do you have a car that can drive from
Amsterdam to Paris?"
It is very basic in javascript, but you will not find 'a javascript' that
will work at once in your current setup.

I know I am not very helpfull untill now. :-)
What you need to do/study:
- naming formelements
- onChange eventhandler to detect a change in some field.
- how to adres a radiobuttongroup
something like:
document.forms['yourformname'].radiogroupname[0].checked = true;

Good luck.

Regards,
Erwin Moller
Sep 5 '05 #2
hygum wrote:
I have combination of radio and select/input:
http://sneleopard.dk/radio.html

Is there a javascript which automatically sets radio 1, when the user
does something with field 1, and automatically sets radio 2, when the
user does something with field 2?


You need to clearly explain your requirements. One radio button should
always be selected, which one should be selected by default?

Should the selected button represent the last field that was changed?
Or does button 1 get selected if field 1 changes and button 2 if field 2
changes? Should both be selected at the same time in this case? If so,
then they probably should be checkboxes not radio buttons.

Further help is dependant on getting more information.

--
Rob
Sep 5 '05 #3
I'm not so stupid as I sound!

The default should be radio 2.

No it's not checkboxes I want. The radiocheck shall change following
the changes in the fields. So it is what Rob suggests: button 1 get
selected if field 1 changes and button 2 if field 2 changes.

Sep 6 '05 #4
I have give it a try, but it doesn't work for me, whats wrong:
http://sneleopard.dk/radio.htm

Sep 6 '05 #5
TRY LIKE THIS ....

Cheers
Ajay.

************************************************** **************************
******************
<HEAD>

<SCRIPT LANGUAGE="JavaScript">

function changeBox(cbox) {
cbox.checked = true;
}

</script>

</HEAD>

<BODY>

<form name=demoform>
<input type=radio name=agreebox1>
<a href="" onClick="changeBox(document.demoform.agreebox1);re turn
false">Clicking this text also checks the radio to the left.</a><input
type=radio name=agreebox2>
<a href="" onClick="changeBox(document.demoform.agreebox2);re turn
false">Clicking this text also checks the radio to the left.</a>
</form>
************************************************** **************************
******************
"hygum" <th*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have give it a try, but it doesn't work for me, whats wrong:
http://sneleopard.dk/radio.htm

Sep 6 '05 #6
hygum wrote:
I have give it a try, but it doesn't work for me, whats wrong:
http://sneleopard.dk/radio.htm


You shouldn't use an A element this way, but for the sake of the example...

<a href="#" onClick="
changeBox('document.demoform.agreebox1.selected');
return false;
">...</a>

For your form, you likely want to use onchange rather than onclick.

You can also use this.form rather than document.demoform if you do as
per your initial original example and put the onchange on a select
element in the same form.
--
Rob
Sep 6 '05 #7
hygum wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
I have give it a try, but it doesn't work for me, whats wrong:
http://sneleopard.dk/radio.htm


I know this is the Javascript NG, but why don't you use the <label> tag instead?

<form name=demoform>
<label>
<input type=radio name=agreebox1>Clicking this text also checks the radio to the left.
</label><br>
<label>
<input type=radio name=agreebox2>Clicking this text also checks the radio to the left.
</label>
</form>
Sep 6 '05 #8
Robi wrote:
hygum wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
I have give it a try, but it doesn't work for me, whats wrong:
http://sneleopard.dk/radio.htm

I know this is the Javascript NG, but why don't you use the <label> tag instead?


Because it is unsuitable - see below (thought the OP's requirements are
pretty vague).

<form name=demoform>
<label>
<input type=radio name=agreebox1>Clicking this text also checks the radio to the left.
</label><br>
<label>
<input type=radio name=agreebox2>Clicking this text also checks the radio to the left.
</label>
</form>


The HTML spec says that in the absence of a 'for' attribute, the label
applies to the enclosed element - however IE doesn't follow the spec.
You must use the 'for' attribute and an id on the radio button.

The HTML spec is also ambiguous about how to deal with sets of radio
buttons (in this case, two sets of one button) where none are checked by
default:

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

Browsers can make their own decision regarding which one is checked by
default - most seem to not check any. The issue then becomes how to
return the form to the original state - once one button is checked,
users can't get back to none checked without either resetting the form
or reloading the page.

It is also a good idea to always enclose attribute values in quotes,
even though they are not always needed.

<form name="demoform" action="">
<label for="agreebox1">
<input type="radio" name="agreebox" id="agreebox1">Clicking
this text also checks the radio to the left.
</label><br>
<label for="agreebox2">
<input type="radio" name="agreebox" id="agreebox2">Clicking
this text also checks the radio to the left.
</label><br>
<input type="reset">
</form>

However, the OP probably wants to make the radio checked based on the
change of another element, in which case a label is not suitable as
putting a second element inside the label creates serious usability issues:

- in Firefox the label keeps putting focus on the radio button
whenever the other elements get focus from clicks but not from keyboard
navigation.

- in IE, the other element is ignored so that clicks on it do not
check the radio button.
--
Rob
Sep 6 '05 #9
sorry i can't get it to work in IE, could you please provide the full
code?

Sep 7 '05 #10
hygum wrote:
sorry i can't get it to work in IE, could you please provide the full
code?


<form name="demoform" action="">
<p>
<input type="checkbox" name="agreebox1">
<a href="#" onClick="document.demoform.agreebox1.checked = true;">
Clicking this text also checks the radio to the left.</a>
<br>
<input type="checkbox" name="agreebox2">
<a href="" onClick="document.demoform.agreebox2.checked = true;">
Clicking this text also checks the radio to the left.</a>
<br>
<input type="checkbox" name="agreebox3">
<select onchange="document.demoform.agreebox3.checked = true;">
<option>
<option>Option 1
<option>Option 1
<option>Option 1
</select>
<br>
<input type="reset">
</p>
</form>

--
Rob
Sep 7 '05 #11
Thank you for the code.

I'm sorry but the checkboxes should be radios, because I only want one
of them checked at a time. Of course I could insert script which
unchecks all, and then checks the specific one, but making checkboxes
behave like radios is less rational as making real radios.

the word "box" in the code stems from the fact that the original script
is in fact with checkboxes.

Could you please make the same with radios instead of checkboxes?

Sep 8 '05 #12

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

Similar topics

0
by: Jean-Marc Blaise | last post by:
Dear all, The LOAD indexing mode is by default, I presume, "autoselect", and the LOAD should choose between REBUILD or INCREMENTAL. In version 7.2 FP11, so in "offline" mode, with a LOAD...
0
by: magister | last post by:
Hello, I am using the Microsoft TreeView control... There is one property called AutoSelect which on the MSDN says "Activates Keyboard Hovering" I have searched the web for what keyboard...
2
by: Tor Inge Rislaa | last post by:
Avoid autoselect in combobox In the load procedure of a form I am filling a combobox with data from a database. The combobox fill the data OK, but it is automatic showing the first item of the...
4
by: Larry Woods | last post by:
I need to implement autoselect in a combobox. Anyone know how? TIA, Larry Woods
6
by: Advo | last post by:
Hi there. Having a few issues and cannot see a way to actually do the following. ive duplicated a simple questionnaire as shown here: http://www.hackeradio.com/questionnaire.html meaning...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
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...
3
by: jahphill | last post by:
Hey. I thought id make a seperate discusion because the other became a bit lengthy and confusing. Aim: Create a php file which works with the script below, which makes the radiobuttons work =D...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
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: 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: 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
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
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...
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...

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.