0
Getting event.preventDefault(); to work?
Post Body
Not sure what I'm doing wrong here, the php script 'name.php' runs fine but it takes it away from the page - but using event.preventDefault() stops everything from running.
test_process.js
$('form#insert_template_form').on('submit', function(event) {
event.preventDefault();
var name = $('input#insert_template_name').val();
$.post('ajax/name.php', {name: name}, function(data) {
$('div#insert_data').text(data);
});
});
controlpanel.php (the relevant bit)
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<h2><u>Insert</u></h2>
<form action="ajax/name.php" name="insert_template_form" id="insert_template_form" method="post">
<textarea rows="10" cols="25" name="insert_template" id="insert_template"></textarea><br/>
Name your template: <input type="text" name="insert_template_name" id="insert_template_name"/><br/>
<input type="submit" name="insert_submit" value="submit" id="insert_submit"/></form>
<div id="insert_data"></div>
<script type="text/javascript" src="test_process.js"></script>
</body>
</html>
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
14,533
Link Karma
10,604
Comment Karma
3,929
Profile updated: 1 day ago
Posts updated: 8 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 10 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/jquery/comm...