2012-12-01 46 views
2
$(document).ready(function() { 
$.validator.setDefaults({ 
    submitHandler: function() { 
     $('#search').submit(function() { 
      var city = $("#city").val(); 
      var adults = $("#adults").val(); 
      var children = $("#children").val(); 
      var SDate = $("#hotelStartDate").val(); 
      var EDate = $("#hotelEndDate").val(); 
      SDate = SDate.substr(6, 4) + '-' + SDate.substr(3, 2) + '-' + SDate.substr(0, 2); 
      EDate = EDate.substr(6, 4) + '-' + EDate.substr(3, 2) + '-' + EDate.substr(0, 2); 
      jQuery(":submit", this).css("display", "none"); 
      jQuery(":submit", this).after("<span class='button nice awesome green large radius'>Searching...</span>"); 
      location.href = 'http://www.dhitrax.com/destination.php?checkin=' + SDate + '&checkout=' + EDate + '&city=' + city + '&adults=' + adults + '&children=' + children; 
      return false; 
     }); 
    }, 
    highlight: function (input) { 
     $(input).addClass("ui-state-highlight"); 
    }, 
    unhighlight: function (input) { 
     $(input).removeClass("ui-state-highlight"); 
    } 
}); 
$().ready(function() { 
    $.fn.themeswitcher && $('<div/>').css({ 
     position: "absolute", 
     right: 10, 
     top: 10 
    }).appendTo(document.body).themeswitcher(); 
    $("#search").validate({ 
     rules: { 
      city: "required", 
      hotelStartDate: "required", 
      hotelEndDate: "required" 
     }, 
     messages: { 
      City: "Please type your destination", 
      hotelStartDate: "Select check in Date", 
      hotelEndDate: "Select check out Date" 
     } 
    }); 
}); 
}); 
+2

WTH..add成的jsfiddle .. – thecodejack

+0

你应该格式化你的代码正确 –

+0

你面对的问题/错误。 。此代码对回答 –

回答

0

你不应该一个事件处理程序绑定到submit事件内的现有submitHandler jQuery验证提供。由于您第一次提交,处理器被绑定,并且您第二次提交处理程序被执行,因此需要两次点击才能提交​​表单。

这应该是作为移动你的代码到submitHandler简单:

$.validator.setDefaults({ 
    submitHandler: function() { 
     var city = $("#city").val(); 
     var adults = $("#adults").val(); 
     var children = $("#children").val(); 
     var SDate = $("#hotelStartDate").val(); 
     var EDate = $("#hotelEndDate").val(); 
     SDate = SDate.substr(6, 4) + '-' + SDate.substr(3, 2) + '-' + SDate.substr(0, 2); 
     EDate = EDate.substr(6, 4) + '-' + EDate.substr(3, 2) + '-' + EDate.substr(0, 2); 
     jQuery(":submit", this).css("display", "none"); 
     jQuery(":submit", this).after("<span class='button nice awesome green large radius'>Searching...</span>"); 
     location.href = 'http://www.dhitrax.com/destination.php?checkin=' + SDate + '&checkout=' + EDate + '&city=' + city + '&adults=' + adults + '&children=' + children; 
    }, 
    highlight: function (input) { 
     $(input).addClass("ui-state-highlight"); 
    }, 
    unhighlight: function (input) { 
     $(input).removeClass("ui-state-highlight"); 
    } 
}); 
+0

谢谢安德鲁,但它不显示搜索button.please帮助我,因为我是新手 – Prashanth

+0

很难说为什么没有看到你的标记。此外,页面正在立即重定向,因此下一页加载速度如此之快以至于看不到它? –