0

i am trying to disable the enter keypress in a form inside a joomla module but i cannot get it to work... This is the code is have.

<script type="text/javascript">
   function stopRKey(evt) {
      var evt = (evt) ? evt : ((event) ? event : null);
      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
      if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
   }

     document.onkeypress = stopRKey;
</script> 

<form id="searchbox" action="<?php echo JRoute::_('index.php'); ?>"                           method="post"         role="search">
    <input type="text" value="" name="searchword" placeholder="<?php echo JText::_('TPL_WARP_SEARCH'); ?>" />
    <button type="reset" value="Reset"></button>
    <input type="hidden" name="task"   value="search" />
    <input type="hidden" name="option" value="com_search" />
    <input type="hidden" name="Itemid" value="<?php echo $itemid > 0 ? $itemid : JRequest::getInt('Itemid'); ?>" /> 
</form>

<script src="<?php echo $warp['path']->    url('js:search.js'); ?>"></script>

<script>
    jQuery(function($) {
       $('#searchbox input[name=searchword]').search({'url': '<?php echo      JRoute::_("index.php?option=com_search&tmpl=raw&type=json&ordering=&    searchphrase=all");?>', 'param': 'searchword', 'msgResultsHeader': '<?php echo   JText::_("TPL_WARP_SEARCH_RESULTS"); ?>', 'msgMoreResults': '<?php echo JText::_("TPL_WARP_SEARCH_MORE"); ?>', 'msgNoResults': '<?php echo JText::_("TPL_WARP_SEARCH_NO_RESULTS"); ?>'}).placeholder();
    });
</script>

I tried different scripts but no luck so far...

Vijay
  • 8,131
  • 11
  • 43
  • 69
Kenny Bloem
  • 91
  • 1
  • 1
  • 6
  • What's wrong, are you getting an error? Nothing happening at all? Something happens, but not what you wanted? – MDEV Aug 23 '13 at 10:25
  • 1
    Maybe this will help: http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-by-hitting-enter. – Dragos Sandu Aug 23 '13 at 10:25

3 Answers3

0

Use event.preventDefault() it prevent default action of the event.

http://api.jquery.com/event.preventDefault/

Avin Varghese
  • 4,340
  • 1
  • 22
  • 31
0
("input").live("keypress", function(e) {
        if (e.keyCode == 13) {
            event.preventDefault();
            return false; // prevent the button click from happening event.preventDefault() or return false, either one is enough
        }
});
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50
  • Look at my site... http://www.kennymassai.com/gamepedia. If you search for batman you get some results in a popup box but when you press enter is opens a searchpage. That is what i want to prevent. So just the results in the popup box and nothing else... – Kenny Bloem Aug 23 '13 at 11:03
0

Change this in html search button :

<input type="text" class="searchButton" value="" name="searchword" placeholder="<?php echo JText::_('TPL_WARP_SEARCH'); ?>" />

Then in script :

$(".searchButton").click(e){
    if (e.keyCode == 13) {
        return false; // prevent the button click from happening
        e.preventDefault(); // prevent default html form submit
    }
}
Roy M J
  • 6,926
  • 7
  • 51
  • 78
  • Thanks Roy, however the form does not respond anymore... You can see my url here... top right... http://www.kennymassai.com/gamepedia/index.php/nintendo-wii-u – Kenny Bloem Aug 23 '13 at 10:41