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>
643 questions
100
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,113
  • 2
  • 7
  • 9
91
votes
16 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
  • 10,880
  • 11
  • 64
  • 92
47
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
  • 899
  • 2
  • 13
  • 22
39
votes
9 answers

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

I have the following:
Darryl Hein
  • 134,677
  • 87
  • 206
  • 257
38
votes
8 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
  • 573
  • 1
  • 5
  • 8
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
  • 584
  • 1
  • 4
  • 12
19
votes
2 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?