Faizan Qadri
Faizan Qadri

Reputation: 248

HOW TO call the JAVASCRIPT function on submit

Following is my javascipt function which i want to call when user click on submit kindly let me know how can i make that call????

    <script type='text/javascript'>
    $(document).ready(function(){

  function(e){

                //stop the form from being submitted
                e.preventDefault();
}
    </script>


<input class="bttonn1" type='submit' onClick="" id='send_message' value='Send The Message'>

Upvotes: 0

Views: 3285

Answers (3)

Luke
Luke

Reputation: 5076

If it's just a button then you can just use functions from within the onclick method:

<input class="button1" onClick="sumbitForm()">
<script type="text/javascript">
function submitForm() {
//Your code here
//If you need to get anything from within a form try using document.getElementById(string)
}

Upvotes: 0

Joe Flateau
Joe Flateau

Reputation: 1225

Just like this: http://jsfiddle.net/joeflateau/9c2Fm/

Listen for submit on the form and preventDefault that

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074335

Use the submit event on the form element, not click on the submit button.

(And your code is incomplete, you're missing the closing } on the handler function, the closing ); on the call to click [which you'd change], the closing } on the ready handler, and the closing ); on the call to ready.)

Upvotes: 2

Related Questions