form submission using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imtiyaz quraish
    New Member
    • Mar 2011
    • 7

    form submission using javascript

    Hi All,

    Is there a way of submitting a form using javascript and without manual click on submit button..?
    the textbox is being filled dynamically and as soon as it gets a value the form should get submitted. Have anyone tried this before?

    It shouldn't be using PHP or ASP or other things.. only HTML and Javascript.

    Thanks,
    Imtiyaz Quraishi
    Last edited by Niheel; Mar 22 '11, 11:42 AM. Reason: merged, info for question
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    to submit a form by JavaScript, use the form’s .submit() method. how to trigger that, is a different matter.

    Comment

    • imtiyaz quraish
      New Member
      • Mar 2011
      • 7

      #3
      Thanks Niheel for editing and adding wht I forgot..
      Thanks Dormilich, but can you let me know what that "Different Matter" could be..?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        that "different matter" is how you call form.submit(). you do not necessarily need a button for that, thus possibilities are numerous.

        Comment

        • imtiyaz quraish
          New Member
          • Mar 2011
          • 7

          #5
          A couple of examples of those would be appreciated.. thanks..

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            e.g. something as fancy as when a field is filled:
            Code:
            field_ref.addEventListener("change", form_ref.submit, true);

            Comment

            • imtiyaz quraish
              New Member
              • Mar 2011
              • 7

              #7
              Thanks Dormilich but as you might have noticed, from my comments and questions, that I'm a newbie when it comes to javascript. It'll be grateful if you can give me a little detailed example which I can understand or elaborate the above one?

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                (actually, when I re-read your OP, my example was quite close).

                for some explanation of the code
                Code:
                field_ref.addEventListener("change", form_ref.submit, true);
                field_ref is the JavaScript object of your text field.
                change is the event type used (there are some other possible types, but I’ve seen this as the best suited)
                form_ref is the is the JavaScript reference to the form element
                addEventListene r is used for standard event handling (does not work in IE)

                for getting the element references (field_ref, form_ref) you typically use document.getEle mentById()

                Comment

                • imtiyaz quraish
                  New Member
                  • Mar 2011
                  • 7

                  #9
                  Thanks once again, will try this tonight and will let you know.. :)

                  Comment

                  Working...