SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Form submit

  1. #1
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form submit

    how do i make a form submit using javascript? without using submit button?

    for example there is an <a href="javascript: submitform();">Submit</a>

    wat should be in my function? thanks!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,803
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    <form name="myform">

    </form>
    <span onclick="myform.submit()">Submit</span>
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:


    Firstly, it is usually considered bad practise to write JavaScript inline with the HTML. The subject of Progressive Enhancement is something worth reading up about; you esentially seperate the JS from the HTML, and use onload events and classes/ids in your HTML to attach JS to HTML.


    But back to the question at hand.

    Code:
    function submitForm()
    {
       document.nameOfForm.submit();
    }
    That's all there is to it. You could adapt this to accept an input parameter of the ID of the form to submit. This way you could use the function on different pages with different forms.

    Hope this helps - but please look into progressive enhancement and seperating JS from HTML. I recommend DOM Scripting by Jeremy Keith as an excellent read on the subject.

  4. #4
    SitePoint Zealot cachobong's Avatar
    Join Date
    Jan 2005
    Location
    cebu
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys!


Bookmarks

Posting Permissions

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