Reputation: 65
I have a form and the submit button is not working. Submit is based on whether someone approves or denies. Also approve deny dropdown needs to pre-populate if someone goes back to tha page by using a temp id from what they entered.
It was working when I use html, but when I add in the php it doesn't work. I think it is because I am not calling selectbasic but I don't know where to add the id. I have tried different variations and can't get it to work.
<form name="iform" id="myform" method="post" onsubmit="submitForm" onreset="" enctype="multipart/form-data" action="submitForm" class="iform">
<label for="Email">Email Address for Officer:</label>
<input class="itext" type="text" value="<?php print $jsonData['Email']; ?>" name="Email" id="Email" />
<br /><br />
<label for="ApproveDeny">Approve or Deny Warrant:</label>
<select class="iselect" name="selectbasic" id="selectbasic">
<?php
$values = array("1" => "Choose an option", "2" => "Approved", "3" => "Denied");
foreach ($values as $value) {
$selectString = '';
if ($value == $jsonData['selectbasic']) {
$selectString = ' selected';
}
print '<option value="' . $value . '"' . $selectString . '>' . $value . '</option>';
}
?>
</select>
<br /><br />
<label> </label><button type="submit2" class="btn btn-success">submit</button>
<input type="hidden" name="tempId" id="tempId" value="<?php print $tempId; ?>" />
</form>
javascript
<script type="text/javascript">
document.getElementById('selectbasic').onchange = function(){
if (this.value=="2") {
newAction='html_form_judge.php';
} else if (this.value=="3") {
newAction='html_form_judgedeny.php';
} else {
newAction='else.php';
}
document.getElementById('myform').action = newAction;
}
</script>
Upvotes: 0
Views: 111
Reputation: 11
You can remove onrest
from your form element.
If you want form reset functionality, you can add an input with the parameter type="reset"
.
I also suggest you rename submit2
to submit
.
Upvotes: 0
Reputation: 30394
You're setting the value of each option to the name, not numerical key, of each element in your array. Do it like this:
foreach ($values as $id => $value) {
...
print '<option value="' . $id . '"' . $selectString . '>' . $value . '</option>';
}
That way, in your javascript, the selected value might actually equal "2" rather than "Approved".
Upvotes: 2
Reputation: 1945
Try ...action="POST"... for your action attribute. That specifies the type of form submission rather than any function to call prior to sending the form.
Upvotes: 0