Form onsubmit is not called at multiple intervals each containing an input

work:

<form class=filter onsubmit="alert('submit');">
    <span class=a></span>
    <span class=b> <input type=text name=b /> </span>
</form>

      

does not work:

<form class=filter onsubmit="alert('submit');">
    <span class=a></span>
    <span class=b> <input type=text name=b /> </span>
    <span class=c> <input type=text name=c /> </span>
</form>

      

By work, what I mean is that when I type some text and hit enter, the onsubmit (simple warning) form is called. Why doesn't it work in the second case? What's the best way to fix this or work around it? I could add a separate onchange event for each html login, or add events via javascript / JQuery. Is this the best approach?


I have a "table" built from divs for rows and spaces for records. The form is one row in the table. Wrapping the inputs inside the slots makes the formatting (mostly column widths / spacing) more uniform. The actual entry element is then set to 80% of the span.

+3
html


source to share


2 answers


  • You should really wrap your attribute values ​​in ""

    s.
  • Depending on the browser, the Enter key may only result in a form submit if the form has exactly one text field or only if there is a submit button. To get around this, you can try this with hidden, input type="submit"

    or use a combination of jQuery keypress

    and submit

    to detect the click enter

    and submit the form programmatically.

    • How can I detect when Enter is pressed on a keyboard using jQuery?


+3


source to share


Where is your submit button?

I just tried this in jsfiddle and it worked :



<form class=filter onsubmit="alert('submit');">
    <span class=a></span>
    <span class=b> <input type=text name=b /> </span>
    <span class=c> <input type=text name=c /> </span>
    <input type='submit' />
</form>
      

+2


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics