[jQuery] problem with submit event
Hello, i would like to trigger submit event for a form when select
option in select box is changed. I also would like to submit the form
when the submit button is pressed.
The problem is that javascript submit event is not working when there
is a submit button. When I remove it everything works like it should.
Heres my test code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
if($_POST)
echo 'form submited:
'. $_POST['selected_type'];
else
echo 'form is not submited';
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#types").change(function() {
$("#submit_form").submit();
});});
</script>
<title>test submit</title>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<form action="index.php" method="post" id="submit_form">
<tr>
<td>
<select id="types" name="selected_type">
<option value="type1">type1</option>
<option value="type2">type2</option>
<option value="type3">type3</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</form>
</table>
</body>
</html>