Php code to remember drop down selection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kingdbag
Forum Newbie
Posts: 22
Joined: Wed Jul 12, 2006 6:22 pm

Php code to remember drop down selection

Post by kingdbag »

Hey guys,

I've been trying to find some php code that will remember what selection I made on a drop down box on a previous html page and automatically have it selected on the next page. Im just posting from test.html to test.html but I want the combo selection that I made on the first page to still be selected on the next page after the post...can this even been done with php?

thanks!
wildwobby
Forum Commoner
Posts: 66
Joined: Sat Jul 01, 2006 8:35 pm

Post by wildwobby »

You can use use SESSION vars
Crazy Coder
Forum Newbie
Posts: 7
Joined: Thu Dec 14, 2006 8:55 am

Post by Crazy Coder »

you can send it in POST method or GET (via Java Script)
kingdbag
Forum Newbie
Posts: 22
Joined: Wed Jul 12, 2006 6:22 pm

Post by kingdbag »

yea im not having problems sending the selection info I just want the drop down to be whatever selection i made so i don't have to use the drop down again to select the same item.

Anyone have a sample I can't seem to figure this out and im starting to angry because this doesn't seem that hard hahaha.... :evil:
brendandonhue
Forum Commoner
Posts: 71
Joined: Mon Sep 25, 2006 3:21 pm

Post by brendandonhue »

echo the "SELECTED" attribute into the <option> tag for the one you want selected.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Save It as Some_filename.html
==============================

Code: Select all

.................................................
<form method="GET" action="rcv.php">
  <select name="sel">
    <option>op1</option>
    <option>op2</option>
  </select>
  <input type="Submit" value="submit">
</form>
................................................
Save it As rcv.php
=========================

Code: Select all

<?php
echo $_GET['sel'];
?>
EDIT|OOPS forgot to put </option>
Last edited by neel_basu on Tue Jan 02, 2007 12:13 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing </option>

...

yes, it's required.
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

Ya You are Right
OOPS I forgot To do It
kingdbag
Forum Newbie
Posts: 22
Joined: Wed Jul 12, 2006 6:22 pm

Post by kingdbag »

Thanks guys think i got it.....i'll let you know and post the code just incase anyone else ever needs the samething or similar....

Thanks!
Post Reply