Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select option...passing variable...newbie question 1

Status
Not open for further replies.

skicamel

Programmer
Dec 24, 2001
126
US
I began to post to the html forum, but they seem distracted with a post about toilets...
As this is in a php page passing variables, maybe it should be posted here anyway...

I've got a search page w/ a pull down list & a text box.

The customer selects one of the options, and types in a search term. The search returns the results to the same page, with the same pull down & text box at the bottom in order to 'search again'. When the results of a search come back, I have the text box at the bottom populate with the original search term, but the pull down will default back to the first option. I would like the value in the pull down that was selected for the search to be visible in the pull down in the results. (The pull down is a list of databases to search... Typically if someone plans to search a second time, they will need the same database)

Any ideas, folks?

As always, thanks for the valuable info.
 
yes, you need to add SELECTED to your <option tag to identify what was initially selected.

so your option list:
echo &quot;
<select name=dropdown>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>&quot;;

but when you write this back to the page you need to verify what was selected first.

heres a small snippet to play with :

<?php
$dropdown1=&quot;$_GET[dropdown1]&quot;;
echo $dropdown1;
echo &quot;<select name=dropdown1>
<option value=1&quot;;
if ($dropdown1==1){
echo &quot; SELECTED&quot;;
}
echo &quot;>1</option>&quot;;
echo &quot;<option value=2&quot;;
if ($dropdown1==2){
echo &quot; SELECTED&quot;;
}
echo &quot;>2</option>&quot;;
echo &quot;<option value=3&quot;;
if ($dropdown1==3){
echo &quot; SELECTED&quot;;
}
echo &quot;>3</option>\n</select>&quot;;
?> ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for the reply... I didn't get it to work the way you had it there, but I only had a short time to play with it before work this morning (though long enough to know the logic is good, just some little issue on my end). I did find another variation while I was at work though (by accident for the most part). I was working at one of our intranet sites and noticed one page I was on was doing exactly what I asked about. I had access to the server, so I grabbed the page. This is how it was handled there...

<select name='dropdown'>
<option value='option1'<?php if(isset($dropdown))
if($dropdown == &quot;option1&quot;) echo &quot; selected&quot;; ?>>option1</option>
<option value='option2'<?php if(isset($dropdown))
if($dropdown == &quot;option2&quot;) echo &quot; selected&quot;; ?>>option2</option>
</select>

Thanks again for the reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top