I am trying to build a JSP page with two drop down lists. The values in the second drop down list should be loaded from the database based on the value selected in the first drop down list. I have two tables 1st one is Customers and in that I have fields : ItemId and CustomerId, my second table is Items and in that I have fields : ItemId and Itemname. So, in my first drop down list I need the values from ItemId in the Customers table to be loaded when the user first accesses the page and when an ItemId is selected in the first drop down list it should pull the Itemname(s) from the Items table and populate the second drop down list. Hope that makes sense. Any help in this matter would be much appreciated.
Now, you do some logic in the back-end to keep the drop down item the user selected to be selected when the page comes back.
So, if I have other form input text fields, checkboxes and what not, that the user has entered, before I send the request to the server to populate the second drop-down, I guess I have to send them back as well, so that the form does not get "reset". Am I right ?
Every time you submit the form, the selected value from each select list gets send with the rest of the form information.
In that demo, I build the select list option tags in an option and then read all of them as one bean property but you could implement the same logic with JSTL and EL or (dare I say it...) scriptlets in your JSP.
I am thinking of collecting the selected values(including text fields, checkboxes, radio buttons, etc) in a bean( I am using Struts) and placing the bean in request scope after the first form submit. I can use these values in the JSP to pre-popluate the form when it gets displayed the second time.
Is there an easier way ? :-) I will look into JSTL and EL.
UP THE IRONS !
Are you here to take over the surface world? Because this tiny ad will stop you!
a bit of art, as a gift, that will fit in a stocking