sammiwei
sammiwei

Reputation: 3200

how to maintain dynamic generated drop down menu items after submit button is clicked.

I have 2 drop down menus, the options in the second drop down menu depend on the first selection, in other words, the options from second drop down is generated after the first options gets selected. My question is, after clicking the submit button, my page will make get call with all the parameters from the form, but how can I keep the second drop down menu's options available and display the previous selected. I have pasted some code to help explain in depth:

function generateOptions(selected) 
  { 
  var Obj = //a dictionary mapping items from first drop down menu with possible options 
  var selected_item = selected.options[selected.selectedIndex].text 
  var options = jsonObj[selected_item]   
  for(var i=0; i<options.length;i++) 
    { 
    jq('#second_menu').append( 
      jq('<option></option>').val('second_menu_option') 
      .html(options[i]) 
    ); 
    } 
  } 

I used the above codes to generate options for the second drop down menu. Please comment if you want some more info to help. Thanks!!!!!

Upvotes: 0

Views: 446

Answers (2)

Taco
Taco

Reputation: 317

Pass the value of the first drop down to $.get("any file as parameter") and create drop down in another file only and get and print it in wherever required.

Upvotes: 1

redDevil
redDevil

Reputation: 1919

do not disturb the form.. it will get reset if the page gets reloaded.. use an ajax GET call to submit the form, that way your select boxes will still have the old values populated in it

Upvotes: 3

Related Questions