This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am currently learning Java in school and we are currently working on some JSP.
It is a basic assignment, but I am having trouble retaining the selected option on the option menu when the user clicks the submit button. It always resets the option menu to the first option listed when the user clicks on submit.
The frequency_value is also only retaining the first value of the row's option menu. It looks like it doesn't care about the other 3 rows option menus.
Ignore the fact that I am outputting the frequency_value into the amount column, I just wanted to see the value the variable was retaining.
Hey Bob...Welcome to the Ranch...
In HTML you make an option selected in a select box by using the keyword "selected".
The above code will select "Monthly" option by default in UI. You have to modify your code such that you identify the selected value at server side and add the "selected" attribute for the appropriate option
^ OP already has selected attribute for `option` element in his code. From above,
Bob, which browser are you using?
Edit: Maybe test your markup in jsfiddle and see if you get the result that you expected.
Joined: Jun 20, 2011
Yep... How I missed that... :)
The problem here is OP is hardcoding "selected" to the first option every time.. Instead it should be programatically determined to which option he had to set the attribute. Nothing to do with browser isnt it?