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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retaining Drop down menu value

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
Hi there im using php mySQL and apache in the normal fashion. on winXP Home..

I have a form which lets users choose values from drop down menus and text fields however, when i mvoe to next page im able to retain the text field values, i.e. using session variables. so when i press the back button it has all the info in the text boxes BUT the drop down menu boxes dont retain there value even if i REgsister them as session variables?

do i need to do something am i missing something?

example of code

<input type=\&quot;text\&quot; name=\&quot;feature1\&quot; value =\&quot; <? echo $feature1; ?>\&quot;>

The above retains its value
BUT
<select name=&quot;propertytype&quot;>
<option value=&quot;flat&quot;>Flat</option>
...
...

this does not
how do i make it so that it will retain its value on screen if i come back to it?

regards

and thanks in advance

sanj
 
these are a bit of a pain to code :

echo &quot;<select name=\&quot;propertytype\&quot;>\n
<option value=\&quot;flat\&quot; &quot;;
if($propertytype == &quot;Flat&quot;){
echo &quot;SELECTED&quot;;
echo &quot;>Flat</option>;
...
...





______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
wow so i got to do that for all the options.. oh well guess it will pay off cos it will look more professional

thanks mate

sanj
 
Hello there i tried the above code,but finding some trouble with it .. for example if i have the followin 2 options available Flat and Detached

how would that be written fully

I know im an idiot
thanks for ur help

sanj
 
sorry to bother i have managed to implement the option block... but wsa wondering if u could help me with another little problem

ok the page where the form is has the options and text boxes etc/....

when i enter stuff in there and then go to next page as in submit it

its fine

but WHEN i go back to the form page for examplei might have made a mistake and change the info and hten press submit again it dont change it keeps/retains the old values???

note i am using session_register for each form element?

can u think why this is happeneing?

regards

and thanks for the help

sanj
 
Hi!

When you register a variable with the session, it is retained once it is set.
Your first submit sets let's say variable $a to &quot;set&quot;.
You return to the previous page and just select variable $b, then submit.
Then you'll have both $a and $b in your session unless you unset $a.

Another thing:
The 'back&quot; button is often the killer of dynamic pages. When you just go back and there is no forced refresh you basically go back into the past. This, however, does not change your PHP session values. You need to rebuild the page so it doesn't come from the browser cache.
 
Ok so i have to change my structure for the page.... damn.. hhehe well hopefully it shouldbe ok when i rebuild it

thanks for the help

sanj

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top