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

supposed to be so simple... - why it's not working as expected ?

abs
Piece of code:

<html>
<head>
</head>
<body>

<script type="text/javascript">
function check()
{
if(document.getElementById('radioA').checked == true)
{
alert('A has just been clicked')
}

if(document.getElementById('radioB').checked == true)
{
alert('B has just been clicked')
}
}
</script>

<form>
<input id="radioA" type="radio" name="test" value="valA"
onfocus="check()">A<br />
<input id="radioB" type="radio" name="test" value="valB" onfocus="check()">B
</form>

</body>
</html>

How to prevent displaying 'A has just been clicked' after clicking the 'B'
radio ? What's wrong with it ?

Thanks for help,
ABS
Nov 28 '05 #1
6 1079
VK

abs wrote:
How to prevent displaying 'A has just been clicked' after clicking the 'B'
radio ? What's wrong with it ?


<html>
<head>
<title>TMP</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/javascript">
function report(who) {
alert(who.id + " just been clicked!");
}
</script>

<form>
<input id="radioA" type="radio" name="test" value="valA"
onclick="report(this)">A
<br>
<input id="radioB" type="radio" name="test" value="valB"
onclick="report(this)">B
</form>
</body>
</html>

;-)

Nov 28 '05 #2
abs said the following on 11/28/2005 12:48 PM:
Piece of code:

<html>
<head>
</head>
<body>

<script type="text/javascript">
function check()
{
if(document.getElementById('radioA').checked == true)
{
alert('A has just been clicked')
}

if(document.getElementById('radioB').checked == true)
{
alert('B has just been clicked')
}
Why are you using gEBI and ID's to access form elements? Use the forms
collection.
Also, there is no need to compare to true, formElement.checked with a
radio button returns true or false (Boolean).

And getting a reference to a Radio Button is not as simple as specifying
its name or ID. Read the FAQ and its Notes, it is covered there in depth.
How to prevent displaying 'A has just been clicked' after clicking the 'B'
radio ? What's wrong with it ?


Bad coding?? <shrug>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Nov 28 '05 #3
abs
VK wrote:
<script type="text/javascript">
function report(who) {
alert(who.id + " just been clicked!");


Smart :) But that's not that what I mean. It's a part of a bigger task and
it was just an example :)

Thanks,
ABS
Nov 28 '05 #4
abs
Randy Webb wrote:
[...]
And getting a reference to a Radio Button is not as simple as
specifying its name or ID. Read the FAQ and its Notes, it is covered
there in depth.


Thanks. I think i just got it from FAQ.

Regards,
ABS
Nov 28 '05 #5
abs
Lee wrote:
The problem is your choice if event handlers. You can't be sure when
onfocus is going to fire. Use "onclick", instead. [...]


Sometimes people do not use mouse to select the form's element. What if
someone uses keyboard to change the radio ?

Regards,
ABS
Nov 28 '05 #6
abs
Lee wrote:
The onclick event still fires if they use the keyboard.


I didn't know... must check it.

Thanks,
ABS
Nov 28 '05 #7

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

Similar topics

7
by: Jeff | last post by:
ok.... i dont know why this wont work. this is going to access DB on web. var1a = Request.Form("h1") var1b = Request.Form("h2") strSQL = "UPDATE matches SET team1a = " & var1a & ", team1b = "...
1
by: dillon | last post by:
Hi everyone I'm writing a javascript/php chat script, but I've run into a problem that is probably very, very simple to fix but I don't have a clue. The problem is with an iframe (should I be...
17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
5
by: Lili | last post by:
I'm having problems creating a simple stored procedure in DB2. Can someone help? Here is the screen dump when I tried to load the stored procedure. Thanks for any help. Create procedure...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
2
by: Ivan Demkovitch | last post by:
Hi! I'm trying to parse RSS news feed with code as simple as possible. Simple XML: <?xml version="1.0"?> <rss version="2.0"> <channel> <item>
0
by: Miguel Dias Moura | last post by:
Hi, i created a script to send form values by email. I am working in ASP.net / VB. The email is sent in HTM format. Well, i everything is working fine but i am getting an error in the...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
2
by: Dragan | last post by:
Hi, We're working in VS 2005, Team edition, if it makes any difference at all (should be up-to-date and all that, but could not guarantee it is 100%). We've implemented a simple generic wrapper...
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
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...
0
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,...

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.