views:

53

answers:

2

Hi, I want to beable to select an option in a select by the value that has been gotten from the session is this possible? So eg in my list:

  • Book
  • Conference
  • Journal

And for example book was in the session so it selects the book in the drop down menu.
Thanks in Advance
Dean

A: 

The HTML attribute selected can be set for the option(s) you want selected.

As far as the session, you didn't describe how you are capturing that information - JavaScript, PHP, etc. If you specify this, you may get some sample code.

Jason McCreary
I wasn't to bothered about sample code just needed to know how to select an option from existing data. Thanks for the answer.
Dean
+2  A: 

i give following example with the help of ruby language. which select the 'Book' when session[:some] contains string 'Book'

<select>
 <option value="Book" <%= 'selected' if session[:some]=="Book" %>>Book</option>
 <option value="Conference"  <%= 'selected' if session[:some]=="Conference" %>>Conference</option>
 <option value="Journal"  <%= 'selected' if session[:some]=="Journal" %>>Journal</option>
<select>

In pure HTML

<select name="">
 <option value="Book" 'selected'>Book</option>
 <option value="Conference" >Conference</option>
 <option value="Journal" >Journal</option>
<select>
Salil
You should use `selected="selected"` or `selected="true"` as valid HTML.
Jason McCreary