dsgni26260 2015-04-12 10:10
浏览 9
已采纳

输入字段未在提交时按提交

I have a problem with submitting a input field. I know I am not the first one who ask this question but I looked at the answers and they didn't work.

I have an input field and a submit button inside a div. I have the code working so that you can search on button press but I can't get submitting on enter press working.

html:

<div class="search singers" action="templates/search/search_singer.php" method="POST">
                <input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/><input class="button" type="submit" value="Search" onclick="search();"/>
    <div id="output" class="output">

    </div>
</div>

Jquery code:

var link = '#search';

//post input
$(function(){
  $(link).keydown(function(e){
      if (e.keyCode == 13) {
        $(link).submit();
        //He detect an enter press but stops then
      }
  });
});

I found the Jquery code on this site
And here a similar question: here

problem sovled I came at the idea that I have a function that makes the ajax request to send the data to php. I now call that function on enter press.

  • 写回答

2条回答 默认 最新

  • duanduji2986 2015-04-12 10:21
    关注

    Your form should be like this. You forgot the form tag in your code, and that's why the form won't submit.

    <div class="search singers">
     <form name='your  form' action="templates/search/search_singer.php" method="POST">
          <input name="search" type="text" id="search" placeholder="Search here for singers" onkeyup="autosug();" data-file="search_singers"/>
          <input class="button" type="submit" value="Search"/>
        </form>
            <div id="output" class="output">
    
            </div>
        </div>
    

    And second thing your autonsan function like this

    <script>
    function autosug() {
        alert("You you are here");
    }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条