473,467 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

using javascript with radio button to disable a text box - does not work in IE

Hi,
I am trying to use javascript, div tag and radio button to
disable/enable a text box. It works fine
in netscape and firefox, but in IE, the text box is not disabled when
the user checks the radio button.

Note that I am using two div statements. Any other solutions also
wellcome.

<html>
<title>Test</title>

<head>
<script type="text/javascript">

function checkButton(rName) {

collection = document.all[rName];
if (collection[1].checked)
{
//document.myform.abutton.disabled = true;
document.getElementById("durfixed").style.display= "block";
document.getElementById("nodurfixed").style.displa y="none";
}
else
{
document.getElementById("durfixed").style.display= "none";
document.getElementById("nodurfixed").style.displa y="block";
}

}
</script>
</head>

<body >
<h2>Radio Button Check</h2>

<form name=myform>
<fieldset style="width:100px">
<legend>Toggle</legend>
<INPUT type=radio name=milestone value="Beta1"
onChange="checkButton('milestone')">Beta 1<br>
<INPUT type=radio name=milestone checked value="Beta2"
onChange="checkButton('milestone')">Beta 2<br>
</fieldset>

<br>

<div id="durfixed" style="display:block;" >
<input type=text name=ename value="">
</div>
<div id="nodurfixed" style="display:none;" >
<input type=text name=noename readonly value="" style="background:
#cccccc" >
</div>
</body>
</form>
</html>
Thanks for the help
Siva

Aug 29 '06 #1
1 24723
s.********@gmail.com wrote:
Hi,
I am trying to use javascript, div tag and radio button to
disable/enable a text box. It works fine
in netscape and firefox, but in IE, the text box is not disabled when
the user checks the radio button.
First, the solution: change your onchange to onclick.

Second, why. Your function is working in IE too. The difference is
tha in IE, the onchange event fires when the control loses focus (which
is as per the W3C spec) whereas other browsers fire a radio button's
onchange essentially as an onclick.

By using onclick, you'll get consistent behaviour across browsers.
Note however that using reload, it is possible to have the state of the
text input out of sync with the radio button selection in some (most?)
browsers. onload you should either run checkButton() or reset the form
to a known state.
--
Rob

Aug 29 '06 #2

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

Similar topics

1
by: Raghuram Banda | last post by:
Hi, Can any one help me, how to create a Radio button using DOM with default one option is selected Thanks in advance
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...
1
by: john | last post by:
I have two different problems: 1. When the user has clicked on a button that is causing the browser to post back to the server, it could take a little while for the new page to show up. So in...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
9
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
8
by: stefano | last post by:
HI, I have aproblem with XHTML radio button. <form name=" form"> <input name="radio" type="radio" onclick="return false" /> <input name="radio" type="radio" onclick="return false" /> <input...
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...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
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
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...
1
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.