jeffery1493 Posted February 17, 2007 Share Posted February 17, 2007 Hi All, What I'm trying to do is, I have code already in place (written by someone else) that pulls data into a dropdown list, "Select the group you want to join:" There is only ever going to be one group, the first option. PHP does a <select onChange=\"document.SelectGroup.submit();\".........> How in the world do you set a PHP dropdown to default to the first option? I've tried every combination and searched websites throughout the land, can't seem to find out how to do this. It does some complex wizardry and pulls data from several tables and whatnot, but all that aside I just want it to automatically pick the first option. Would appreciate any advice if anyone out there has done this before-----thanks! jeffery1493 Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 The same way you have a default option in a regular select... <select name="selectbox" size="1"> <option selected>Option 1</option> <option>Option 2</option> </select> Quote Link to comment Share on other sites More sharing options...
jeffery1493 Posted February 17, 2007 Author Share Posted February 17, 2007 'Option 1' is the text for the option labeled 'Option 1'. This is definitely in the right direction. The problem is, my option list is constructed out of a spaghetti tapestry of six pages of code and variables, often the unfortunate result when coders are allowed to program too long on the same language. I wonder if there is a way to just tell PHP <option selected>"{whatever value is the first option}"</option>, making it execute on load. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 It would be much easier for us to help if you could post the code related to getting the data to populate the drop down, as well as the code that generates the drop down. Quote Link to comment Share on other sites More sharing options...
jeffery1493 Posted February 17, 2007 Author Share Posted February 17, 2007 Thanks, sorry. Well, I'm unable to reach my web hosting company's site to cut and paste code, for some reason.....great. Basically it constructs a lengthy variable called $optiongroups using $optiongroups .="<form name=\"Select Group\" method = \"post\" action =\"" . append_sid("./lwtopup.".$phpEx[<--THIS IS THE NAME OF THE PROGRAM]) . "\"><input type=\"HIDDEN\" name=\"UpdateGroupBtn\" value="true\"><label for =\"group_id\" ><select onChange=\"document.SelectGroup.submit();\" id=\"group_id\" name=\"group_id\" class="droplist\" size=\"1\">"; then: $optiongroups .= "<option value=\"-1\">" . 'Select a group' . </option>"; So you first see "Select a group", and then it pulls only one option from the database into the drop down list, since there is only one option in the database. Then when you pick option #1, it executes the document.SelectGroup.submit() and goes on its merry way for many more acres of code after. I think if there were some way just to make it prepick the first option, instead of asking, you wouldnt' have to change anything else. Something like in VB where you go to Properties and set the default option, but I know this isn't object oriented and I never was a Windows fan anyway...........although its hard to wean yourself off that way of thinking once its forced on you.......... Theres a ton of other code, but that is where I think the action is. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 If there is only one group (option in the select box), and you have to chose a group in order to proceed in the app, but that option is already chosen for you, there would be no way to chose that option and the form never gets submitted by the onchange event, which stops progress. Hopefully that makes sense. Quote Link to comment Share on other sites More sharing options...
jeffery1493 Posted February 17, 2007 Author Share Posted February 17, 2007 It seems so crazy to have an online business and when they click to join, they see a menu "Please select an option: 1: Join!" It reminds me of taping a sign to a door, "Welcome to our company. Please choose a doorknob below to open ------> " Oh well, it looks like I'm going to have to live with it. I wonder if you could "echo" a selection somehow. Frustrating................... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.