Note that there are some explanatory texts on larger screens.

plurals
  1. POalert() triggers form submission
    primarykey
    data
    text
    <p>I am trying to <em>eliminate the "enter event" default value</em> on <code>type=text</code>, which triggers submit on the form. I do so with the following:</p> <pre><code>var onEnter = function(values){ $("#"+values['id']).keydown(function(e){ if (e.which == 13) { event.preventDefault(); var function_to_call = window[values['function']]; if(typeof function_to_call === 'function'){ if(values['parameters']!= null){ parameters = values['parameters']; var args; if(typeof parameters === 'string') args = parameters.split(','); else args = new Array(parameters); function_to_call.apply(window, args); } else function_to_call(); } return false; } }); } </code></pre> <p>The code that matters for <em>taking away the default event</em> is </p> <pre><code>event.preventDefault(); return false; </code></pre> <p>The rest of code just calls a function with parameters or no parameters. The thing is, inside the functions called, there´s a condition that triggers an alert. Here´s the deal:</p> <ol> <li>If <strong>alert is not triggered</strong>, <code>[enter]</code> does not trigger form submission</li> <li>if <strong>alert is triggered</strong>, form submission is triggered</li> </ol> <p>The function called on every <code>type=text</code> is the same, and here is the alert condition:</p> <pre><code>...... if(!regex_match(item)){ alert("Solo son posibles los siguientes caracteres: '.' ',' 'a-z' 'a-Z' '0-9' y ' '"); return; } ..... var regex_match = function(text){ regex = /^[_., 0-9a-záéíóúñ]+$/i; return regex.test(text); } </code></pre> <p>Things tried:</p> <ul> <li>"<code>return false;</code>" after <code>alert(...)</code>; </li> </ul> <p>I am new to javascript, could anyone point out why this could be happening? Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload