There is a problem, check <input type="text" name="b1" id="right_answer"> for a string, that is, the user will need to drive in an answer, without gaps anything extra complicated, but I got a blunted at the js test stage. I wrote this code to check

 function Check_Radio(){ var count = 0 var ex1 = document.getElementById("right1"); if (ex1 == "test"){ count++; } console.log(count); } 
 <input type="text" name="b1" id="right1"> 

I can not understand how to compare it right. Tell me please

  • document.getElementById ("right1"). value - Stranger in the Q
  • and what to compare ?? - Vitaly Shebanits

2 answers 2

Here is an example of a small

 var input = document.getElementById('input'); input.addEventListener('input', check) function check() { if (this.value == 'test') { console.log('succes') } else { console.log('error') } // Или более короткая запись (Тернарный оператор) // this.value == 'test' ? console.log('succes'): console.log('error') } 
 <input type="text" name="b1" id="input"> 

  • Thank you, it works great. I forgot a little for the eventlistener - Dmitry Kotovsky
  • @ Dmitry Kotovsky is always welcome;) - ANYWAYCODE

 var input = document.getElementById("inp"); input.addEventListener("input", function(){ console.log(this.value === "text" ? "true" : "false"); }); 
 <input type="text" id="inp" /> 

  • Thanks It works. Blighted a little bit - Dmitry Kotovsky