Onchange submit the form in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • techbytes
    New Member
    • May 2010
    • 36

    Onchange submit the form in javascript

    hai,


    I have a form in which there is a dropdown list.
    When i change the value of dropdown,the form should be submitted and the selected value should be also be passed on form submission.
    Depending on the selected value another set of values is displayed.


    i donnot know how to do this.


    suggestions required.
  • Tawnos
    New Member
    • Aug 2010
    • 1

    #2
    So when the dropdown changes the form is submitted which refreshes the page. Sometimes, however, another dropdown is displayed as well?
    Last edited by Tawnos; Aug 31 '10, 02:46 PM. Reason: typo

    Comment

    • techbytes
      New Member
      • May 2010
      • 36

      #3
      hai,

      yes,Depending on the selected value,another dropdown is populated.
      For that ,I want to get the selected id of the first dropdown and submit the form .
      Based on the id,values are fetched from the displayed on the second dropdown.

      I donotknow ,how to submit the form on onchange and get the selected id and passit to java function.

      suggestions req.

      Comment

      • kovik
        Recognized Expert Top Contributor
        • Jun 2007
        • 1044

        #4
        Are you sure that you want to submit the form every time that another option is selected?

        You could use AJAX and populate the next dropdown based on the returned data. Or, better yet, place all of the possible values in the original JavaScript and display the dropdowns based on those values. You could use nested arrays to store all of the options.

        Submitting the form every time the option is changed seems like overkill since the user will have to wait for the entire page to load again rather than a small AJAX response or no load at all.

        Comment

        • techbytes
          New Member
          • May 2010
          • 36

          #5
          hai,

          I used ajax to populate the values,but the entire page is written as response in the dropdown.
          I donotknow how to write the particular value in the dropdown in ajax.

          Comment

          • kovik
            Recognized Expert Top Contributor
            • Jun 2007
            • 1044

            #6
            So, what you are saying is that submitting the dropdown changes more than just one element? In that case, why do you want to submit it whenever it is changed? What if people make an accidental selection?

            I would force them to hit "Submit" to ensure that they are submitting the correct value.

            Comment

            • techbytes
              New Member
              • May 2010
              • 36

              #7
              hai,


              thanx.

              can u tell me how to particular response in the div in contrast to entire page in the div.

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                If you only want to update part of a page, you can use AJAX to communicate with the server, and then alter the page according to the server response.

                There are lots of tutorials out there on AJAX.

                Comment

                Working...