JQuery AJAX with Validation - Scripts


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*** Send Colleague Inivtation - STARTS ***/
  2. function colleagueInvitation(form_obj)
  3. {
  4. var message = $("#message_box_colleague").val();
  5.  
  6. // first hide any error messages
  7. $('.error').hide();
  8. $('.common_error').html('');
  9.  
  10. var selected_items = $("#colleague_selected_email_container div").size()
  11. // Form Validations
  12. if(selected_items==0)
  13. {
  14. $(".common_error").html('Select atleast one Colleague');
  15. $("#selected_emails:tr first").focus();
  16. }
  17. else if(message == "") {
  18. $("label#message_box_colleague_error").show();
  19. $("label#message_box_colleague_error").html('This field is Required');
  20. $("#message_box_colleague").focus();
  21. return false;
  22. }
  23. else
  24. {
  25. var str = $("#"+form_obj.id).serialize();
  26. $("#tab4_sub_div2").hide();
  27. $("#temp_loader").show();
  28. $.ajax
  29. ({
  30. type: "POST",
  31. url: "community/send_invitation.php",
  32. data: str,
  33. success: function(msg)
  34. {
  35. $("#temp_loader").hide();
  36. $("#tab4_div").show();
  37.  
  38. $("#tab4_webmail_notice").css('display','block');
  39. $("#tab4_webmail_notice").html(msg);
  40. $("#tab4_webmail_notice").fadeIn('slow')
  41. .animate({opacity: 1.0}, 3000)
  42. .fadeOut('slow', function() {
  43. $("#tab4_webmail_notice").slideUp();
  44. });
  45. }
  46. });
  47. }
  48. }
  49. /* ----- ENDS ----- */
  50. /* ----- HTML PART ----- */
  51.  
  52. <br clear="all"/><p><label class="error" for="attach_link_url" id="attach_link_url_error" style="display:none; color:red; font-weight:normal;"></label></p>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.