0

This is a .php file and I have tried several things to make this work, but I am new to javascript. When I run this with the document.write enabled, it shows me that the onclick event for the button is working. But for whatever reason, I cannot find any information about how to write to an input text element within a form. Does anyone know how this should work? Do I have to put the button inside the form? Thanks.

<?php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
function setValue() {
    //document.write("122.0000");
    document.getElementById("someid").innerHTML="222.0000";
}
</script>
<center>
<button onclick="setValue()">Write value</button><br>
<center><form action="something.php" method="post" id ="inputForm">
Value: <input type="text" id="someid" /><br>
<input type="submit" />
</form>

1 Answers1

2

Change

document.getElementById("someid").innerHTML="222.0000";

to

document.getElementById("someid").value="222.0000";

This will set the value of the text input to 222.0000 instead of trying to change the innerHTML, which is the content between the opening and closing tags (non-existent for inputs).

chris97ong
  • 6,870
  • 7
  • 32
  • 52