Questions tagged [onsubmit]

onSubmit is the HTML event called when a submit button is pressed on a HTML form. The event is also called the form.submit() function is called. It can be used to trigger JavaScript to validate the form, pre-process its data, or block the submission altogether.

Here's simple onSubmit example demonstrating its use:

<html>
<head>
    <script type="text/javascript">
        function greeting()
        {
            alert("Welcome " + document.forms["frm1"]["fname"].value + "!");
        }
    </script>
</head>
<body>
    What is your name?<br />
    <form name="frm1" action="submit.htm" onsubmit="greeting()">
        <input type="text" name="fname" />
        <!-- when the "Submit" button is clicked, the greeting() function above is called -->
        <input type="submit" value="Submit" />
    </form>
</body>
</html>
721 questions
117
votes
4 answers

Setting onSubmit in React.js

On submission of a form, I'm trying to doSomething() instead of the default post behaviour. Apparently in React, onSubmit is a supported event for forms. However, when I try the following code: var OnSubmitTest = React.createClass({ render:…
Lucas du Toit
  • 1,283
  • 2
  • 8
  • 9
105
votes
18 answers

Testing if value is a function

I need to test whether the value of a form's onsubmit is a function. The format is typically onsubmit="return valid();". Is there a way to tell if this is a function, and if it's callable? Using typeof just returns that it's a string, which…
Glen Solsberry
  • 11,960
  • 15
  • 69
  • 94
51
votes
10 answers

React.js: submit form programmatically does not trigger onSubmit event

I want to submit a React form after a click on a link. To do so I need to submit the form programmatically if the link is clicked. my problem is : onSubmit handler is not being fired after the form submit . Here is a code snipped that I made for…
Ahmed Kooli
  • 713
  • 1
  • 6
  • 10
49
votes
3 answers

HTML form action and onsubmit issues

I want to run JavaScript user validation on some textbox entries. The problem I'm having is that my form has the action of going to a new page within our site, and the onsubmit attribute never runs the JavaScript function. Is there a better…
James Brown
  • 919
  • 3
  • 13
  • 22
43
votes
9 answers

Should jQuery's $(form).submit(); not trigger onSubmit within the form tag?

I have the following:
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
25
votes
3 answers

How to check with jQuery if any form is submitted?

I have a page with a lot of forms, and the user is going to pick something on that page. When the user does, I need to place that element somewhere else, much like a shopping cart really. But I can't seem to get more than the first form on the page…
Lozzano
  • 582
  • 1
  • 5
  • 12
24
votes
5 answers

Whats the difference between onclick and onsubmit?

It's not like I haven't googled it... But still I couldn't understand when onsubmit is used and when onclick is used?
user3636516
  • 305
  • 1
  • 2
  • 10
23
votes
2 answers

Form onsubmit versus submit button onclick

UPDATE From @BrendanEich ‏ @mplungjan onclick of submit just falls out of that being a button; form onsubmit is clearly better. Which would be the reasons to ever use the onclick of a submit button to determine whether or not the form should be…
mplungjan
  • 169,008
  • 28
  • 173
  • 236
21
votes
3 answers

javascript onsubmit not working

I am trying to make a javascript function work on submitting the form, the function doesnt seem to run. Can anyone help?