I'm trying to update the action property of the form tag by calling a JavaScript function when a user presses the submit button. The action property is updated depending on what is selected in the select box called "proceed". However the following script does not work and I don't know why.
Javascript:
<script type="text/javascript">
function updateAction() {
<?php
if (empty($errors) && isset($_POST['submit'])) {
echo 'document.newStudent.action = document.newStudent.proceed.value';
} else {
echo 'document.newStudent.action = "newStudent.php"';
}
?>
}
</script>
<form name="newStudent" method="POST" onsubmit="updateAction()">
Select box which is much further down in my code:
<?php //PROCEED
echo '<tr>';
echo '<td><p>Proceed To:</p></td>';
echo '<td>
<select name="proceed">
<option value="newSchedule.php">add student\'s schedule</option>
<option value="newStudent.php">add another student</option>
<option value="staff.php">staff page</option></td>';
echo '</tr>';
?>