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 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line