473,785 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Radio Event Not Registered

MC
Question,
Why does the following code register the event for input type button but not
radio? (And how do I make this happen?)
Thanks,
MC

<HTML>
<FORM name='x' action=''>
<input type='radio' name='rbTest' id='YES_1' value='1'>YES
<input type='radio' name='rbTest' id='NO_1' value='0'>NO
<input type='button' name='btnTest' id='btnTestid' value='test'>
</FORM>
<SCRIPT LANGUAGE="Javas cript" type="text/javascript">
document.x.btnT est.onclick = doTest;
document.x.rbTe st.onclick = doTest;
function doTest(e) {
alert('doTest') ;
}
</SCRIPT>
</HTML>
Jul 22 '08 #1
3 1314
On Jul 22, 3:51 pm, MC wrote:
Question,
Why does the following code register the event for input
type button but not radio? (And how do I make this happen?)
Thanks,
MC

<HTML>
<FORM name='x' action=''>
<input type='radio' name='rbTest' id='YES_1' value='1'>YES
<input type='radio' name='rbTest' id='NO_1' value='0'>NO
<input type='button' name='btnTest' id='btnTestid' value='test'>
</FORM>
<SCRIPT LANGUAGE="Javas cript" type="text/javascript">
document.x.btnT est.onclick = doTest;
document.x.rbTe st.onclick = doTest;
<snip>
If you have multiple like-named form controls (usually radio buttons)
then referencing them by name results in a collection of all of those
like-named controls. Setting an - onclick - property on a collection
object is probably harmless but is also not useful.

You would need to loop through the collection and assign the - onclick
- listener to each form control element in the collection in tern.
Jul 22 '08 #2
MC
Henry,
Thank you for pointing this out. Adding the following resolved the issue.
MC

function addRadioEvent(e ) {
for (var i=0; i < e.length; i++) {
e[i].onclick = myEventClick;
}
}
Jul 22 '08 #3
Henry wrote:
On Jul 22, 3:51 pm, MC wrote:
>Question,
Why does the following code register the event for input
type button but not radio? (And how do I make this happen?)
[...]
<HTML>
<FORM name='x' action=''>
<input type='radio' name='rbTest' id='YES_1' value='1'>YES
<input type='radio' name='rbTest' id='NO_1' value='0'>NO
<input type='button' name='btnTest' id='btnTestid' value='test'>
</FORM>
<SCRIPT LANGUAGE="Javas cript" type="text/javascript">
document.x.btnT est.onclick = doTest;
document.x.rbTe st.onclick = doTest;
This is not Valid markup and so is not supposed to work in the first place.
<snip>
If you have multiple like-named form controls (usually radio buttons)
then referencing them by name results in a collection of all of those
like-named controls. Setting an - onclick - property on a collection
object is probably harmless but is also not useful.

You would need to loop through the collection and assign the - onclick
- listener to each form control element in the collection in tern.
It suffices and is much more efficient to assign the `click' event listener
to the `form' element object or another common ancestor element object
instead, because the `click' event bubbles in all known DOMs:

function doTest()
{
// ...
}

and then

<form ... onclick="doTest ()">
...
</form>

or

document.forms["x"].addEventListen er("click", doTest, false);

or

document.forms["x"].onclick = doTest;

Note that the third approach is proprietary (for `onclick'). In contrast
to the second, standards-compliant approach, it requires some work if a
potential primary event listener is not to be replaced.

As obvious by the first approach, the `form' element does not need a name.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jul 23 '08 #4

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

Similar topics

2
18609
by: Matt | last post by:
I have radio buttons on a form, and when the user makes the selection, it will trigger the event and send the form to the web server and print the selected value. In Case 1, I just use submit button, without any event handling, and it works fine. However, in Case 2, which is what I am trying to do, it has the problem that even when the user clicks the button, it won't show the value automatically. But wait until user selects another...
6
5191
by: amith | last post by:
hi, i have some 10 radio buttons meant to take the rating from the user. ex: 1 2 3 4 5 6 7 8 9 10 looks O O O O O O O O O O 1 2 3 4 5 6 7 8 9 10 features O O O O O O O O O O
6
18831
by: HD | last post by:
Hi. I have an asp page with radio buttons and a combobox... when the user clicks a radio button, I want the form to submit so I can execute the ASP code in order to change the list shown in the combobox... I have 2 radiobuttons: <input type="radio" name="terriprod" value="E">E <input type="radio" name="terriprod" value="D">D I have tried adding an OnClick event to each of the radio button...
2
3493
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 "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...
1
8857
by: Jerry | last post by:
We have a 10-question quiz for kids, each question being a yes or no answer using radio selections. I'd like to keep a current total of yes's and no's at the bottom of the quiz (if the user selects yes to question 1, the total of yes's increases by 1). I've been searching for a while but I'm not sure I'm searching with the right keywords. Can anyone direct me to a source I can review to learn how to do this? Thanks! --
1
2979
by: Joe Attardi | last post by:
Hi all, On a form on one of my pages I have two <select> elements, and each one is paired up with a radio button. The idea is to choose an item from one list or the other and select the radio button of the list you want to use. I'm using JavaScript to automatically select the radio button corresponding to a list when you click on the list (using the onclick event handler). Is that the best event to change on, or should this
3
2499
w33nie
by: w33nie | last post by:
I want to disable the text boxes, captain_name and captain_email, but only if the radio button, captain_guarantee, has NOT been checked. how do i do this? <form name="formTeamApplication" action="teams_process.php" method="post" onSubmit="validate()"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width='75'><span class='Body'>Team Name:</span></td> <td width='150'><input width="150"...
4
3092
by: Z.K. | last post by:
I started a forms application and I put on the form three buttons. In the functions for the radio buttons I put in a single messagebox like: MessageBox("Hello 1") MessageBox("Hello 2") MessageBox("Hello 3")
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
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
10085
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
9947
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...
1
7494
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
6737
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
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4045
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
2877
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.