SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto submit form once field entered

    can someone tell me how to submit a form once an entry has been put in a specific field?
    for example, user enters value in a field and then it get's submitted.

  2. #2
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function submit(formId) {
        var form = document.getElementById(formId);
        form.submit();
    }
    Then you have to execute this function on some event or whatever. The main thing is to determine if the field if filled. How? When it loses focus?

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnjohn2 View Post
    can someone tell me how to submit a form once an entry has been put in a specific field?
    for example, user enters value in a field and then it get's submitted.
    Hi John,

    Like Mike I'm wondering how you will know the user is ready entering? If the user types the <ENTER> key, most browsers will auto-submit the form, even if no 'submit' button is present.

    But in case you like to have the form submitted when the user types <TAB> or otherwise changes the focus (e.g. clicking on another page element), you could use the very short and reliable code below that I use in a lot of my pages:

    <input type="text" onchange="this.form.submit();" />

    Greetz, Vincent


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
  •