maqskywalker
asked on
JavaScript selector
On button click event how do I assign a variable value to textbox whose Id starts with txtemployee
If
I want to do it with JavaScript, not jQuery.
See I have 3 texboxes.
They are called:
txtemployee1
txtemployee2
txtemployee3
Normally I do this with jquery selector. But I'm trying to learn to do the same only using JavaScript.
If
I want to do it with JavaScript, not jQuery.
See I have 3 texboxes.
They are called:
txtemployee1
txtemployee2
txtemployee3
Normally I do this with jquery selector. But I'm trying to learn to do the same only using JavaScript.
ASKER
I tried it with chrome and it works, but I tried it with Internet Explorer 11 and it's not working.
Do you know a better way so it works on both Chrome and Internet Explorer?
Do you know a better way so it works on both Chrome and Internet Explorer?
probably the selector by attribute value's substring is not supported. Can you assign an unique class to all those input boxes (say "txtemployee_class") and select them with
var tes = document.querySelectorAll("input.txtemployee_class");
ASKER
I don't think the issue is by id or by class. I tried by class and still get the same error in internet explorer.
The error message i get in internet explorer is : Object doesn't support property or method 'forEach'
I think IE doesn't support foreach.
https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
Is there a way to re-write this part without using forEach?
tes.forEach(function (te) {
te.value = 'value'
});
The error message i get in internet explorer is : Object doesn't support property or method 'forEach'
I think IE doesn't support foreach.
https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
Is there a way to re-write this part without using forEach?
tes.forEach(function (te) {
te.value = 'value'
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
ASKER
Thanks , works on chrome and ie just fine.
forEach on nodelists is indeed not supported by any IE
https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
https://jsfiddle.net/23wx9nar/7/
Open in new window