0

I´m trying to change an input value automatically. This is what i've got.

<input hidden="" id="inp" type="text hidden" value="YES" />

<script type="text/javascript">
function checkInputValue() {
    var files = {
            'YES': 'audio/timbre.mp3',
            'NO': 'audio/timbre2.mp3'
    };
    var sound = new Audio(files[$('#inp').val()]);
    sound.play();
}
checkInputValue();
</script>

There is a hidden input in HTML with a default value "YES". I'd like to change this value to "NO" automatically when 2 seconds has passed.

Anyway doing this?

Thanks.

Yash
  • 11,486
  • 4
  • 19
  • 35

2 Answers2

0

Simply add this at the bottom of your code

setTimeout(function(){
    document.getElementById("inp").value = "NO";
}, 2000)

setTimeout will execute provided function callback after given time. Remember time should be in milliseconds 2000ms == 2s

Vipin Kumar
  • 6,441
  • 1
  • 19
  • 25
0

You could query the element with document.getElementById, and change its value.

document.getElementById('inp') //because its 'id' is 'inp'

To delay for 2 seconds, use the setTimeout function and pass in 2000 milliseconds.

setTimeout(function () {
  document.getElementById('inp').value = 'NO'
}, 2000)
mykeels
  • 590
  • 5
  • 9