Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser freezes when trying to click on disabled radio button

Status
Not open for further replies.

citress

Programmer
Nov 1, 2006
1
US
Hi, I have some javascript code that the disables a group of radio buttons when a particular option is selected. This disabling of radio buttons is done onblur.

For example, here are two radio buttons:

<input type="radio" name="Test" value="no" onblur="disableGroup();" />
<input type="radio" name="Test" value="yes" />

// javascript
function disableGroup() {
var radioBtns = document.getElementsByName('Test');
for (i = 0; i < radioBtns.length; i++)
radioBtns.disabled = true;
}

The problem is that the browser freezes when I click on the first radio button, AND THEN click on the second radio button. At the second mouse click, two events take place - first radio button loses focus and second radio button receives focus. I know that the first radio button did loose focus (b/c the two radio buttons were disabled) and that the second radio button must be trying to receive focus, but I'm guessing this is confusing the browser as the second radio button was already disabled by javascript on the onblur event.

If I move disableGroup() to onclick, the browser would not freeze. However due to certain constraints, the disabling of radio buttons has to take place at onblur or some kind of event where the radio buttons loose focus.

Also, if I print out an alert in disableGroup() like so:

// javascript
function disableGroup() {
var radioBtns = document.getElementsByName('Test');
for (i = 0; i < radioBtns.length; i++)
radioBtns.disabled = true;
alert("FINISH");
}

the browser would not freeze. I figured it has something to do with the window losing focus. So I tried:

// javascript
function disableGroup() {
var radioBtns = document.getElementsByName('Test');
for (i = 0; i < radioBtns.length; i++)
radioBtns.disabled = true;
window.blur();
window.focus();
}

and the browser also won't freeze. However I can't use this work around as the window flashes for a brief second and it is rather obvious.

I have tried things like:

// javascript
function disableGroup() {
if (radio button is not disabled) { // pseudo code
var radioBtns = document.getElementsByName('Test');
for (i = 0; i < radioBtns.length; i++) {
radioBtns.blur();
radioBtns.disabled = true;
}
window.focus();
}
}

but none worked.

Does anyone know any reason why this is happening or how to get around the freezing??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top