This question already has an answer here:
I was trying something in a web page. Basically I have a form with two select tags. When I change the value of the first select I want to submit the form with only the selected selects (in this case the first one). Below the code and error. What am I doing wrong.
Thank you.
I expected to get the content of the $_POST variable, instead I get nothing. In the browser's consolle I have this error "0: unable to find element" on the javascript line "var myForm = document.getElementById("myForm");"
<html>
<script type="text/javascript" src="prova.js"></script>
<body>
<form id ="myForm" action="prova.php" method="post">
<select name="first" onchange="prova();">
<option value="NULL">Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<br>
<select name="second">
<option value="NULL">Select</option>
<option value="1.1">1.1</option>
<option value="1.2">1.2</option>
<option value="2.1">2.1</option>
<option value="2.2">2.2</option>
<option value="2.3">2.3</option>
</select>
<div class="btn">
<button type="submit" value="Submit" name="submit">Search 🔍</button>
</div>
</form>
</body>
</html>
function prova() {
var myForm = document.getElementById("myForm");
myForm.submit();
}
<?php
print_r($_POST);
?>
</div>