Как реализовать ввод ключевых действий в форме

0

В моем приложении php я использую текстовое поле и кнопку [поиск].

когда я вхожу в некоторые данные, и я нажимаю клавишу Enter, действие кнопки не работает.

может кто-то помочь в этом.

Мой код вроде,

    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    <script>
    function clearerrormessage()
         {  
        document.getElementById('info').innerHTML="Enter a keyword to find prospective customer";

         }
    function submi()
      {
      /*$('#keyword').keyup(function(e) {
          if (e.keyCode == 13) {
           $('#form1').submit();
         }
       });*/
 keyword1 =document.getElementById('keyword').value;

    //var unvalidkey = new Array("is","am","a","b",'',"are","was","were");
  var unvalidkey = new Array("is","am","a","b",'',"are","was","were","+","/","%",".","&","\\","\"","'","?","#");
for(keyitem in unvalidkey) 
{
    if(unvalidkey[keyitem]==keyword1)
    var f=0;
}  
if(f==0)
{
    document.getElementById('info').innerHTML = '<h3><font color = red>Please enter a valid keyword to search</font></h3';
    return false;
}

  keyword=keyword1.replace(' ','_');
  $.post( "<?php echo base_url() ?>ajax/followsearch.php", { keyword  : keyword })
  .done(function( data ) {
  $("#content1").html("<div id ='content'></div>");
  $('#content').scrollPagination(

  { 

nop     : 30, // The number of posts per scroll to be loaded
offset  : 0, // Initial offset, begins at 0 in this case
error   : 'No Results To Display!', // When the user reaches the end this is the message that is
                            // displayed. You can change this if you want.
delay   : 500, // When you scroll down the posts will load after a delayed amount of time.
               // This is mainly for usability concerns. You can alter this as you see fit
scroll  : true // The main bit, if set to false posts will not load as the user scrolls. 
               // but will still load if the user clicks.
  }
        );

  });

  }

    </script>
    </head>
    <body>
    <form id="form1" name="form1" action="" />
    <div id="followkeyword">
    <input type="text" style="width:300px;height:26px" name="keyword" id="keyword"  onClick="clearerrormessage()" />
    <div id="info1"><span id="info">Enter a keyword to find prospective leads</span>                                
    </div>                    
   </div>   
   <div id="followperloc">

   <input type="button" name="mysubmit" id="mysubmit" value="Display my prospective leads" onclick="return submi()"/>           
   </div>
   </form>

   </body>
   </html>

этот код правильно работает при нажатии кнопки. Но мне нужно также работать в режиме ввода ключа. Пожалуйста, помогите мне..

  • 0
    почему ваша функция называется submi() ? Это кажется таким странным
Теги:

1 ответ

1

Проверьте код ключа события 13, чтобы обнаружить ключ ввода. Попробуйте следующее:

Html: используйте onkeypress вместо onclick потому что onclick - mouseevent.

<input type="button" name="mysubmit" id="mysubmit" value="Display my prospective leads"
 onkeypress="return submi(event)" onclick="return submi(event)"/>  

JavaScript:

function submi(event) {
event.which = event.which || event.keyCode;
if(event.which == 13 || event.which == 1) {
    // wrap up your entire code here
}
}
  • 0
    спасибо за ответ .. но это не работает
  • 0
    Теперь нажатие кнопки тоже не работает ......
Показать ещё 5 комментариев

Ещё вопросы

Сообщество Overcoder
Наверх
Меню