Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Jak wyłączyć reagowanie <input type='submit'> na ENTER ?
Forum PHP.pl > Forum > XML, AJAX
noyo_pl
Witam,
znalazłem w globalnej wiosce autosuggest w ajaxie, czytał z pliku, ale przerobiłem go, aby czytał z bazy danych. Działa smile.gif.

Tylko mam mały problem gdy wyszukuje usera, a następnie strzałkami wybieram go podświetlam



i naciskam enter to następuje wywołanie przycisku
  1. <input type='submit' value='wyślij' name='submit' >


Jak zrobić, aby przycisk "wyślij" nie reagował na Enter ?



index.php
  1. <?php
  2.  
  3. echo "<form enctype='multipart/form-data' action='".$_SERVER["REQUEST_URI"]."' method='POST'>
  4.  
  5. <input type='text' name='user_do' value='' SIZE=55 id='testinput_xml'>
  6.  
  7.  
  8. <script type='text/javascript'>
  9. var options = {
  10. script:'/zapytania/autosuggest.php?json=true&limit=6&',
  11. varname:'input',
  12. json:true,
  13. shownoresults:false,
  14. maxresults:6,
  15. callback: function (obj) { document.getElementById('testid').value = obj.id; }
  16. };
  17. var as_json = new bsn.AutoSuggest('testinput', options);
  18.  
  19.  
  20. var options_xml = {
  21. script: function (input) { return '/zapytania/autosuggest.php?input='+input+'&testid='+document.getElementById('testid').value; },
  22. varname:'input'
  23. };
  24. var as_xml = new bsn.AutoSuggest('testinput_xml', options_xml);
  25. </script>
  26.  
  27.  
  28. <input type='submit' value='wyślij' name='submit' >
  29.  
  30. </form>";
  31. ?>






/zapytania/autosuggest.php
  1. <?php
  2. include('../config.php');
  3. include('../function/function.php');
  4.  
  5.  
  6.  
  7. /*
  8. note:
  9. this is just a static test version using a hard-coded countries array.
  10. normally you would be populating the array out of a database
  11.  
  12. the returned xml has the following structure
  13. <results>
  14. <rs>foo</rs>
  15. <rs>bar</rs>
  16. </results>
  17. */
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. ///MYSQL
  26.  
  27. $wues = mysql_query("SELECT * FROM users WHERE enable_usuniete='0' and id>'1'") or die("Blad w zapytaniu!");
  28. while($rues = mysql_fetch_array($wues)) {
  29. $wsuserz = $wsuserz.":".$rues['login'];
  30. }
  31. $aUsers = explode(':',$wsuserz);
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /// $aInfo = array(
  39. /// ""
  40. /// );
  41.  
  42.  
  43. $input = strtolower( $_GET['input'] );
  44. $len = strlen($input);
  45. $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : 0;
  46.  
  47.  
  48. $aResults = array();
  49. $count = 0;
  50.  
  51. if ($len)
  52. {
  53. for ($i=0;$i<count($aUsers);$i++)
  54. {
  55. // had to use utf_decode, here
  56. // not necessary if the results are coming from mysql
  57. //
  58. if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
  59. {
  60. $count++;
  61. $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
  62. }
  63.  
  64. if ($limit && $count==$limit)
  65. break;
  66. }
  67. }
  68.  
  69.  
  70.  
  71.  
  72.  
  73. header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  74. header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
  75. header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  76. header ("Pragma: no-cache"); // HTTP/1.0
  77.  
  78.  
  79.  
  80. if (isset($_REQUEST['json']))
  81. {
  82. header("Content-Type: application/json");
  83.  
  84. echo "{\"results\": [";
  85. $arr = array();
  86. for ($i=0;$i<count($aResults);$i++)
  87. {
  88. $arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
  89. }
  90. echo implode(", ", $arr);
  91. echo "]}";
  92. }
  93. else
  94. {
  95. header("Content-Type: text/xml");
  96.  
  97. echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?><results>";
  98. for ($i=0;$i<count($aResults);$i++)
  99. {
  100. echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
  101. }
  102. echo "</results>";
  103. }
  104. ?>
phpmens
dodaj obsługe zdarzeń w JS na enter
wiiir
dodaj zdarzenie na enter na tej liscie co ci sie pojawia... z tego co mi sie wydaje to zostanie wybrany dany element i pojdzie sumbit z ta wartoscia... bo chyba chodzi o to ze jak dajesz enter to leci ci "ad" a nie "admin"
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.