preventDefault(); not working on submit

preventDefault(); not working on submit

Hello,

I am new to using jQuery and can't seem to load data from another page without navigating to that page. My code is probably wrong somewhere so if someone could tell me what is wrong that'd be fantastic!

Script I am using
  1. <script type="text/javascript">
  2. /* attach a submit handler to the form */
  3. $("#myform").submit(function(event) {
  4.  
  5.  /* stop form from submitting normally */
  6.  event.preventDefault();
  7.  
  8.  /* get some values from elements on the page: */
  9.  var $form = $( this ),
  10.  name = $form.find( 'input[name="name"]' ).val(),
  11.  detail = $form.find( 'input[name="detail"]' ).val(),
  12.  email = $form.find( 'textarea[name="email"]' ).val(),
  13.  url = $form.attr( 'action' );
  14.  
  15.  /* Send the data using post and put the results in a div */
  16.  $.post( url, { name, detail, email },
  17. function( data ) {
  18. var content = $( data ).find( '#content' );
  19. $( "#results" ).empty().append( content );
  20. }
  21.  );
  22. });
  23. </script>
Form I am using:
  1. form name="myform" id="myform" action="add_topic.php" method="POST">
  2. <div class="box">
  3. <h1>Reply Form</h1>
  4. <!-- The Name form field -->
  5. <label for="name" id="name_label">
  6. <span>Name:</span>  
  7. <input type="text" class="input_text" name="name" id="name" size="30" value=""/>
  8. </label>
  9. <!-- The Email form field -->
  10. <label for="email" id="email_label">
  11. <span>Email:</span>  
  12. <input type="text" class="input_text" name="email" id="email" size="30" value=""/> 
  13. </label>
  14. <!-- The Detail form field -->
  15. <label for="detail" id="detail_label">
  16. <span>Detail:</span>
  17. <textarea class="message" name="detail" id="detail" rows="4" cols="24" value=""/></textarea>
  18. <!-- Hidden value used to retrieve new posts -->
  19. <!-- <input type="hidden" name="gpost" id="gpost" value="<?php // print $gpost; ?>"/> -->
  20. <!-- The Submit button -->
  21. <input type="submit"  class="button" name="submit" id="submit" value="Send">
  22. </label>
  23. </div>
  24. </form>
Output desired:
  1. <div id="content">
  2. <?php
  3. echo "Successful<BR>";
  4. echo "<a href=main_forum.php>View your topic</a>";
  5. ?>
  6. </div>
Any help?