Reputation: 153
I have an HTML select with several options. One of them is selected by default, but I would like to be able to change which one is selected. I found out how to do it using javascript, but I would like to do it using PHP as the information used to set it is stored in a PHP $_SESSION
variable.
Upvotes: 0
Views: 219
Reputation: 33391
Assuming the data is stored in $_SESSION['data']
, then you can set the selected
attribute.
<select name="dropdown">
<option> <?php if ($_SESSION['data'] == "test"){ echo " selected "} ?> value="test">
test
</option>
</select>
Upvotes: 3
Reputation: 610
<select>
<option<?php if($condition_one) print 'selected'; ?>>One</option>
<option<?php if($condition_two) print 'selected'; ?>>Two</option>
<option<?php if($condition_three) print 'selected'; ?>>Three</option>
</select>
Upvotes: 1
Reputation: 2619
You'll need to learn PHP, I recommend starting here.
Start Googling around for PHP tutorials. After you learn basic PHP, this will be easy for you.
Upvotes: 0