Results 1 to 8 of 8

Thread: Submitting forms through javascript

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Newcastle,UK
    Posts
    66

    Submitting forms through javascript

    Can anyone help me

    We call the submittion of a form through javascript, would anyone be able to explan why when the form is submitted, the onsubmit function in the form is completely ignored and we never get into this?

    Thanks

    Sarah

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I can't reall yhelp you with any code (just don't post anything huge). Here is how to submit using JS, this will do the same as pressing the submit button:
    Code:
    <html>
    <body>
    <script type="text/javascript">
    function submit_this_form() {
    document.getElementById('myFrm').submit()
    }
    </script>
    <form id="myFrm" action="myPage.cgi" method="post">
    <input type="text" value="insert name here><br >
    <input type="text" value="insert e-mail here><br >
    <input type="button" value="submit (through JavaScript)" onClick="submit_this_form()">
    </form>
    </body>
    </html>
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Newcastle,UK
    Posts
    66
    Thanks for the reply

    That bit works on but if i show you the top line to my form

    <FORM onsubmit="return myOnSubmitEventHandler(); calculateCheckBoxes();" ID="searchFormID" action="res_results.asp" target="results" method=post style="display:inline">

    The submit in the javascript ignores the two javascript functions that i would like to call

    Any ideas?

    Thanks

    Sarah

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    maybe the function that calls the submitting of the form could run throught those functions first.
    Have I helped you? Please Rate my posts.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Newcastle,UK
    Posts
    66
    For now that is how i have implemented it

    I was wondering if anyone has seen any documentation to support my theory that it will ignore this part of the function if submitting via javascript rather than through the enter button or a submit button on a form

    Sarah

  6. #6
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I haven't seen any documentation, but I can see why they would make it like that. since the function is called submit(), that's what it does, submit the form.

    I think you'll have to keep it as it is, running the functions from the other one.
    Have I helped you? Please Rate my posts.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Location
    Newcastle,UK
    Posts
    66
    Just found this in MSDN

    "The submit method does not invoke the onsubmit event handler."

    As in the submit method via javascript

    Thanks for all your help - nice to know you are not alone when trying to solve these problems

    Sarah

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Even if it worked, it wouldn't invoke the second function. The return prevents that.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width