i have a simple post that works when i assign the click to an anchor but not to the forms submit. also when i take the post out of the submit wrapper it works but the click from the form isnt. i must be overlooking something simple!!
any help would be appreciated
Code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//$("a").click(function() {//this works
$("#myform").submit(function() {// this doesnt
//$.post('process.php', $("#myform").serialize(), function(data) {
$.post( 'process.php', function( data ) {
$('#results').html(data);
});
});//myform
});
</script>
</head>
<body>
<a style="cursor:pointer;">click</a>
<form name="myform" id="myform" action="">
<!-- The Name form field -->
<label for="name" id="name_label">Name</label>
<input type="text" name="name" id="name" size="30" value=""/>
<br>
<!-- The Email form field -->
<label for="email" id="email_label">Email</label>
<input type="text" name="email" id="email" size="30" value=""/>
<br>
<!-- The Submit button -->
<input type="submit" name="submit" value="Submit">
</form>
<!-- We will output the results from process.php here -->
<div id="results"><img src='red.jpg'/><div>
</body>
</html>
process.php
Code:
<?php
//print "Form submitted successfully: <br>Your name is <b>".$_POST['name']."</b> and your email is <b>".$_POST['email']."</b><br>";
echo "<img src='grey.jpg'/>";
?>
Bookmarks