How to change Label Value using javascript -
I want to change the label label from '0' to the label below 'Thank you', at the checkbox click event.
& lt; Input type = "hidden" name = "label 206451" value = "0" /> & Lt; == "txt206451" class = "swatch_text" for label & gt; Chestnut leather & lt; / Label & gt; & Lt; Input type = "checkbox" name = "field 206451" class = "swatch_check" id = "txt206451" value = "selected" />
Javascript is as follows.
var cb = document.getElementById ('field206451'); Var label = document.getElementById ('label206451'); Cb.addEventListener ('click', function (evt) {if (cb.checked) {label.value = 'thanks';} and {label.value = '0';}}, wrong);
But is this not working any thoughts?
You are taking the name
in document. GetElementById ()
should be your cb
txt206451
( id attribute ) is not a name
attribute.
or
You can get it by
var cb = document.getElementsByName ('field206451') [0]; // first one
OR
var cb = document.getElementById ('txt206451');
and to set the value in hidden usage as follows
var cb = document.getElementById ('txt206451'); Var label = document.getElementsByName ('label206451') [0]; // Get the first index console.log (label); Cb.addEventListener ('change', function (evt) {// use change here.) If it (ne.sectioned) {label.value = 'thanks'} and {label.value = '0'}}, is not wrong .;
Comments
Post a Comment