javascript - Jquery submit form then redirect not working -


i have found many posts can't work life of me. on submit of form, need code 1) submit form , 2) redirect 1 of locations inside case statements. can form submit without cases , can form redirect, can't both. please tell me on right track have code in wrong spot, have been staring @ way long , have hit roadblock.

$("#submitbtn").click(function (event) {         event.preventdefault();         var validator = $(this).closest("form").kendovalidator({             messages: {                 required: function (input) { return getrequiredvalidationmessage(input) },                 custom: function (input) { return getinvalidvalidationmessage(input) },             },             rules: {                 custom: function (input) {                     var minlength = $(input).attr('data-minlength');                     var required = $(input).attr('required');                     if (typeof minlength !== typeof undefined && minlength !== false && ((typeof required !== typeof undefined && required !== false) || $(input).val().length > 0)) {                         var minlength = $(input).data('minlength');                         return $(input).val().length >= minlength;                     } else {                         return true;                     }                 }             }         }).data("kendovalidator");         if (validator !== undefined) {             if (validator.validate()) {                 $("aspnetform").submit();                  if ($("aspnetform").submit()){                     switch(document.getelementbyid('interests').value){                         case "stair-lifts":                         window.location.href="/catalog/online-catalog-category/15522/stair-lifts";                         break;                          case "wheelchair-ramps":                         window.location.href="/catalog/online-catalog-category/15521/ramps";                         break;                          case "roll-in-barrier-free-showers":                         window.location.href="/catalog/online-catalog-category/15529/bathroom-safety";                         break;                          case "walk-in-tubs":                         window.location.href="/catalog/online-catalog-category/15529/bathroom-safety";                         break;                          case "patient-lifts-ceiling-lifts":                         window.location.href="/catalog/online-catalog-category/15523/patient-lift";                         break;                          case "wheelchair-lifts":                         window.location.href="/catalog/online-catalog-category/15525/wheelchair--scooter-lifts";                         break;                          default:                         window.location.href="/"; // if no selection matches redirected home page                         break;                     }// end of switch                  }              } else {                 $('.k-invalid:first').focus();                  $('.k-invalid').blur(function () { if (this.checkvalidity()) { $('.k-invalid:first').focus(); } });             }         } else {             $(this).closest("form").submit();         }         }); }); 

you shouldn't using .submit() this. since you're using jquery, should use ajax request, formatted this:

$("#submitbtn").click(function (event) {     $.ajax({         url : "/your/url", // whatever url you're submitting goes here         type : "post",         data : yourdata, // whatever data you're sending goes here         success : function(data) {             // whatever want on success goes here         }     }); }); 

you make switch in url part of function ajax query executes on success.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -