Jump to content

Default values in PHP dropdown lists


jeffery1493

Recommended Posts

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

 

 

Link to comment
Share on other sites

'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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...................

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.