Page 1 of 1
pass value from select list to new page
Posted: Tue Mar 21, 2006 3:01 pm
by cincana
I have a select list and want to capture the row selected to pass to another page. I can't quite get it to work.
If I have a list called 'lstID' and the user selects row 5 (value five).
The form link is page2.php?ID=<? echo $_POST['lstID']; ?>
what the link ends up being when submitted is page2.php?ID=five&submit=submit
Is there a good tutorial or reference or help?
Thanks
Posted: Tue Mar 21, 2006 3:04 pm
by nickman013
What do you want to do?
You can just submit the form using the GET method. And then you can $_GET the form value that you want.
Same with post. Just $_POST it. That is if register globals is off. If it is on then you get just do $value. But write every code like register globals is off.
Posted: Tue Mar 21, 2006 3:10 pm
by feyd
if you don't inject the "value" attribute into the select, it will submit the index of the row selected. (row five will be four in the submission, as it starts counting at zero)
Posted: Tue Mar 21, 2006 3:36 pm
by cincana
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
This is the code:
Code: Select all
<body>
<form action="page2.php?<? echo $_GET['lstID']; ?>" name="listingg" id="listingg">
<select name="lstID" id="lstID">
<option value="one">1</option>
<option value="two">2</option>
<option value="three">3</option>
<option value="four">4</option>
</select>
<input type="submit" name="Submit" >
</form>
</body>
And this is what it's trying to pass now:
http://xxx.com/page2.php?lstID=two&Submit=Submit+Query
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Mar 21, 2006 3:55 pm
by feyd
as I said before, removing the value attribute from the select (the options, specifically) will submit the index chosen.