ds34222 2014-08-24 09:21
浏览 50

通过回车键和提交按钮提交表格

Hi I have form and following things are bothering me:

1. Form does not submit on pressing enter. 2. When i press enter in input field then Search Now button needs to be pressed twice to search places.

Form is displayed as below:

<form method="POST" id="mylocform" action="">
  <h3 class="animated slideInLeft delay-2">
   <input type="text" placeholder="Start Typing Your Location" id="geocomplete" 
    style="color:black;width:100%;padding:5px;height:45px;border-radius:5px" 
    autocomplete="off" class="chkmeloc" onblur="checkmylocform()"/></h3>
 <input type="submit" class="btn btn-default btn-lg animated fadeInUpBig delay-3"
 style="color: black;background-color: #FFF;border-color: #FFF;"  
 value="Search Now!"/>
</form>

Validation goes like below:

$(document).ready(function(){ 
  $("form#mylocform").submit(function(event) {
  event.preventDefault();
  validate();
  });
});

function checkmylocform(){
  var checkOdlen = $(".chkmeloc").val().length; 
    if(checkOdlen==0){
    $(".chkmeloc").css("border-color","#F05F68");
    $(".chkmeloc").focus();
    $(".chkmelocmess").html('<button type="submit" class="btn btn-default
     btn-lg" style="background: #FFF;color:red">
     <i class="fa fa-warning text-red"></i>
     Select Your Location</button>');
    return false;
}
else{
    $(".chkmeloc").css("border-color","#0C9");
    $(".chkmelocmess").html('<input type="submit" class="btn btn-default 
    btn-lg" style="color: black;background-color: #FFF;border-color: #FFF;"
    value="Search Now!"/>');
    return true;
}
}

function validate(){
$.each($('form :input'),function(){
    $(this).blur().change();        
});
if(!checkmylocform()){
    return false;   
}
else{

    submitform();
}
}

Submit Form has code to submit form via ajax as below. Please help me to get out of this situation.

  • 写回答

3条回答 默认 最新

  • duanmorong9597 2014-08-24 09:24
    关注

    look at this site: http://tjvantoll.com/2013/01/01/enter-should-submit-forms-stop-messing-with-that/ the site says that enter key is automaticly a submit in al browser

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)