I have multiple inputs I want to discriminate according to whether the user enters a value in it or not.
<input type="text" class="foo"> <br/>
<input type="text" class="foo" value = "D"> <br/>
//and so on..
<button onclick="calculate()">Hightlight</button>
The code I wrote only works with attribute values, instead of detecting "manually" typed values before launching the function :
function calculate() {
var allinputs = document.querySelectorAll('input[value][type="text"]:not([value=""])');
var myLength = allinputs.length;
for (var i = 0; i < myLength; ++i) {
allinputs[i].style.backgroundColor = "lime";
}
}
I only want to detect the inputs in which the user typed something when he submits it through the highlight button. Is there a way to do it in pure javascript ?
Here is my fiddle : https://jsfiddle.net/Lau1989/Lytwyn8s/
Thanks for your help