How to update an input text with JavaScript?

button, javascript, textbox

Solution

<script language="javascript"> 
     function check() {
          document.getElementById('txtField').value='new value here'
     } 
</script>

<input id="txtField" type="text" name="b"> <input type="button" onClick=" check(); ">

This will do. I gave it an ID, and used getElementById('txtField') using the id, and updated it's value.

Problem

I have this simple code that speaks for itself. ``` <script language='javascript"> function check() {} </script> <div id="a">input type="text" name="b"> <input type="button" onClick=" check(); "> ``` All I want is that when I press the button, the text field gets a value updated to it. I tried using `b.value=" C "` but it doesn't seem to work.

Original source