CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    73

    form submission with Javascript

    Hello!
    I am searching over the net for quite a long, but I have almost no idea concerning Javascript so I can't figure out the solution to my problem...
    I have a form that show a drop-down menu, which takes all its values through a Mysql database via PHP. What I want to do is to submit the form to the next page (from index.php ---> retrieve_data.php) without the need of a "Submit" button.
    When the user selects one of the given options, automatically he will be redirected to retrieve_data.php?id=5 for example...

    Thank you in advance!

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: form submission with Javascript

    Call the document then the form then submit.

    Code:
    document.FORMNAME.submit()
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Dec 2004
    Posts
    438

    Re: form submission with Javascript

    For some reason this just doesn't work for me. If I click my button which launches this nothing happens.

    Code:
    function submitForm()
    {
      document.markForm.submit();
    }
    Code:
    <form method="post" name="markForm" id="markForm" action="update_entry.php">
    Code:
    <input type="button" name="submit" value="Update Marks" class="SubmitButton" onClick="submitForm()" />
    I can't see anything wrong with that. My button takes the place of my submit as you can see.

    Edited:
    Eventually found out that I was getting this error in Firefox error console and looked it up:

    "Error: document.markForm.submit is not a function"

    What I found out is the the submit button with the name of "submit" can clash with the submit function. I changed the submit button's name and it worked fine.
    Last edited by Nibinaear; January 31st, 2007 at 04:38 AM.

  4. #4

    Re: form submission with Javascript

    You have the concept, it is done like you wrote. But little observation:

    put
    Code:
    onClick="submitForm();"
    instead of
    Code:
    onClick="submitForm()"
    but i've no idea if it would fix the problem, since the error happen while submitting!
    David Domingues at [email protected]. Feel free to visit http://www.webrickco.com

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

Featured