I have the following code in PHP:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php $value = $_POST['Field1'] ?>
<input type="text" id="Field1" name="Field1" value="<?php echo $value ?>">
<input type="button" value="ButtonValue" onclick="SubmitFunction()">
</form>
And some function in JavaScript:
<script>
function SubmitFunction(){
//... do some stuff here
//But here I need to assign value to Field1:
document.getElementById("Field1").setAttribute("value", "Some value");
document.form.submit();
}
</script>
When this code loads for the first time, it says there is undefined index Field1. It's absolutely right.
But when I set attribute value to this field using SubmitFunction(), page reloads and it still can't find Field1 ! This is my problem.
I noticed that in pure HTML code the initial form looks like:
<form>
<input type="text" id="Field1" name="Field1" value>
<input type="button" value="ButtonValue" onclick="SubmitFunction()">
</form>
Where is my problem (except brain)?