1
<form name="test_form">
    <input id="demo" type="text" value=""> 
</form>



<button onclick="data()">GO</button>
<script>
var x=document.getElementById("demo");  
function data()
  {
    x.innerHTML="TEST"; 
  }
</script>

I am trying to input JavaScript function into input field but I've got a problem with that, nothing is happening, any ideas how to fix it?

1
  • 1
    First of all your code doesn't do what you think it does. You do not use .innerHTML to change the value of an input tag. Commented Nov 27, 2012 at 18:13

2 Answers 2

1
x.innerHTML="TEST"; 

should be

x.value="TEST"; 
Sign up to request clarification or add additional context in comments.

1 Comment

@Neal, Please enlighten as to what else is wrong. I think this is the main thing. Even if it isn't, I don't think this warrants a downvote, it surely fixes the OP's problem. jsfiddle.net/Fan5v
0
<script>

function data()
{
  var x=document.getElementById("demo");
  x.value="TEST"; 
}
</script>
<form name="test_form">
  <input id="demo" type="text" value=""> 
</form>
<button onclick="data();">GO</button>

http://jsfiddle.net/vdAY7/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.