javascript - document.activeElement doesn't work as expected on Chrome, what are the alternatives? -


hi,

i want check/uncheck checkboxes same class disable\enable associated text fields when checking/unchecking checkbox.

i managed write code using document.activeelement , document.getelementsbyclassname that'll that, except doesn't work on chrome. it's reported bug in chrome returns body instead of actual activeelement unless activeelement text field.

is there workaround can use until bug fixed?

my code:

js:

function changeall(variable) {     var current = document.activeelement;     var checkboxes = variable + "_g";     var text = variable + "_v";     var i;     if (current.checked === true) {         (i = 0; < document.getelementsbyclassname(checkboxes).length; i++) {             document.getelementsbyclassname(checkboxes)[i].checked = true;         }         (i = 0; < document.getelementsbyclassname(text).length; i++) {             document.getelementsbyclassname(text)[i].disabled = false;         }     } else {         (i = 0; < document.getelementsbyclassname(checkboxes).length; i++) {             document.getelementsbyclassname(checkboxes)[i].checked = false;         }         (i = 0; < document.getelementsbyclassname(text).length; i++) {             document.getelementsbyclassname(text)[i].disabled = true;         }     } } 

html:

<input type="checkbox" class="y_g" onclick="changeall('y')"> <input type="text" class="y_v" disabled> <input type="checkbox" class="y_g" onclick="changeall('y')"> <input type="text" class="y_v" disabled> <br> <input type="checkbox" class="x_g" onclick="changeall('x')"> <input type="text" class="x_v" disabled> <input type="checkbox" class="x_g" onclick="changeall('x')"> <input type="text" class="x_v" disabled> 

pass in reference

html:

<input type="checkbox" class="y_g" onclick="changeall(this,'y')"> 

javascript:

function changeall(current, variable) {     //var current = document.activeelement; 

ideally not using inline events.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -