nvee Posted October 31, 2009 Share Posted October 31, 2009 Hey Guys thanks for everyones help so far. This site and its users are oozing awesomness. I am busy with a php script for editing users, of which 1 field is the TITLE of the person (mrs, miss, ms) and it is displayed as a dropdown box. I have written the code which allows you to get the values in the fields for the rest of the fields, but I am not sure how to get PHP to change the actual selected dropdown box. The only thing I can think of is to have a if else statement for each option in the select dropdown, but I assume that when someone has a lot of options in their SELECT dropdown, it will be a lot of work and I am sure someone knows the trick behind this Any suggestions? Link to comment https://forums.phpfreaks.com/topic/179730-solved-getting-php-to-ammended-the-selected-in-option-field/ Share on other sites More sharing options...
waynew Posted October 31, 2009 Share Posted October 31, 2009 PHP won't be able to change the values in your select boxes without a page refresh. Your best best would be to use Javascript if you're wanting it to happen automatically. PHP works on the server side. Link to comment https://forums.phpfreaks.com/topic/179730-solved-getting-php-to-ammended-the-selected-in-option-field/#findComment-948276 Share on other sites More sharing options...
nvee Posted October 31, 2009 Author Share Posted October 31, 2009 Hey Wayne Thanks for your reply. I think you may have misunderstood me and reading my own post, i probably left out some important info. Navigation starts with a page called student.php which then gives you a list of students. Once you click on their name, it opens a new page called student_info.php which looks like the student registration form, but obviously this time just with the student values already entered into the form for quick editing. I have managed to already get all of the other forms right (and have gotten the dropdown right) but the dropdown way I am taking to me would appear to be alot of unneccesary work, but hey ... IT WORKS I was actually merely wondering if anyone else had a better way of getting this to work. Here is my code: <select name="title" value="<?php echo "$title"; ?>" id="title"> <?php if ($result["title"] = "Mr.") { echo "<option value=\"Mr.\" selected=\"selected\">Mr.</option>"; } else { echo "<option value=\"Mr.\">Mr.</option>"; } if ($result["title"] = "Mrs.") { echo "<option value=\"Mrs.\" selected=\"selected\">Mrs.</option>"; } else { echo "<option value=\"Mrs.\">Mrs.</option>"; } if ($result["title"] = "Miss") { echo "<option value=\"Miss\" selected=\"selected\">Miss</option>"; } else { echo "<option value=\"Miss\">Miss</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/179730-solved-getting-php-to-ammended-the-selected-in-option-field/#findComment-948280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.