jemz Posted May 17, 2012 Share Posted May 17, 2012 How do i set value in my select option, and i want this value is from the database. I tried this but it's not working <select name="status" value="<?php echo $status; ?>"> <option value=""></option> <option value="Active">Active</option> <option value="Inactive">Inactive</option></select> Can you help me on this.Thank you. Link to comment Share on other sites More sharing options...
Ingolme Posted May 17, 2012 Share Posted May 17, 2012 You set the value by adding selected="selected" to the option that contains the value you want. Link to comment Share on other sites More sharing options...
jemz Posted May 17, 2012 Author Share Posted May 17, 2012 You set the value by adding selected="selected" to the option that contains the value you want. Hi,thank you for the quick reply,is this what you mean?<select name="status" > <option value="<?php echo $status; ?>" selected="selected"></option> <option value="Active">Active</option> <option value="Inactive">Inactive</option></select> Link to comment Share on other sites More sharing options...
Ingolme Posted May 17, 2012 Share Posted May 17, 2012 No, this is what I mean: <select name="status"> <option value=""></option> <option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option> <option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select> Link to comment Share on other sites More sharing options...
jemz Posted May 20, 2012 Author Share Posted May 20, 2012 No, this is what I mean:<select name="status"> <option value=""></option> <option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option> <option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select> Hi sorry for the late reply.Thank you so much it's working.you are very great. Link to comment Share on other sites More sharing options...
jemz Posted May 20, 2012 Author Share Posted May 20, 2012 No, this is what I mean:<select name="status"> <option value=""></option> <option value="Active" <?php if($status == 'Active') { echo 'selected="selected"'; } ?>>Active</option> <option value="Inactive" <?php if($status == 'Inactive') { echo 'selected="selected"'; } ?>>Active</option></select> Hi,can you help me please on this i am stuck in this,i could not select the day.Thank you in advance.<select name="day" > <?php for($d=1;$d<=31;$d++) echo '<option f($day==$d) selected='selected'>'.$d.'</option>'; ?> </select> Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 Try <?phpfor($d=1;$d<=31;$d++){ echo '<option'; if($day==$d){ echo ' selected="selected"';} echo '>'.$d.'</option>'; } ?> Link to comment Share on other sites More sharing options...
jemz Posted May 20, 2012 Author Share Posted May 20, 2012 Try <?phpfor($d=1;$d<=31;$d++){ echo '<option'; if($day==$d){ echo ' selected="selected"';} echo '>'.$d.'</option>';} ?> Hi,it's working where did you learn this kind of coding i mean the way you do in your echo?Thank you so much it helps me. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 20, 2012 Share Posted May 20, 2012 Done this kind of think many times with select and option elements before, not exactly like this, but similar. Link to comment Share on other sites More sharing options...
jemz Posted May 20, 2012 Author Share Posted May 20, 2012 Done this kind of think many times with select and option elements before, not exactly like this, but similar. Is it possible also in this select example inside the select option cat orchid mouse Karl Jupiter if the user will select the cat it will display to the texfield "Animal" and if the user will select Ochid it will Display to the textfield "plant" is this possible? Link to comment Share on other sites More sharing options...
Ingolme Posted May 20, 2012 Share Posted May 20, 2012 You need Javascript to do that. It's not one or two lines of code, either. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.