473,748 Members | 8,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4173
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 radiobuttongrou p
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="JavaS cript">

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

</script>

</HEAD>

<BODY>

<form name=demoform>
<input type=radio name=agreebox1>
<a href="" onClick="change Box(document.de moform.agreebox 1);return
false">Clicking this text also checks the radio to the left.</a><input
type=radio name=agreebox2>
<a href="" onClick="change Box(document.de moform.agreebox 2);return
false">Clicking this text also checks the radio to the left.</a>
</form>
*************** *************** *************** *************** *************** *
*************** ***
"hygum" <th*********@gm ail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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('docu ment.demoform.a greebox1.select ed');
return false;
">...</a>

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

You can also use this.form rather than document.demofo rm 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******** *************@g 14g2000cwa.goog legroups.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******** *************@g 14g2000cwa.goog legroups.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#radi o>

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

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

Similar topics

0
1508
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 INSERT, we got the LOAD choose the REBUILD despite the lack of pages in the tablespace (we had 2Million 16K page free, but this was not enough). Is the behavior the same in V8.1 (I've noticed the READ ACCESS mode only
0
1078
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 hovering is and cannot find anything actually what this means..... Can anyone tell me what this property actually does I would be
2
3280
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 list as the text. How can I avoid the first item in the list to be selected as default? I want the textbox of the combo to be left empty until the user select an item. My Code below:
4
3412
by: Larry Woods | last post by:
I need to implement autoselect in a combobox. Anyone know how? TIA, Larry Woods
6
12385
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 there are 8 questions, each with 8 possible answers. Each row of the answers has its own name ie: question12_answer1 - question12_answer8
1
6891
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 grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
10
6101
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
3
2846
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 Right, when say mp3 radio button is selected, and say BLA is typed in the text box. I would like it to open up...
11
2277
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 6.something I think and running as a service, Using NoteTab Pro as an IDE (works well). If you need more, just ask. In one functioning form:
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9319
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.