boneXXX Posted May 14, 2007 Share Posted May 14, 2007 Could someone help me on using select list with php Such as: echo"<table align='center' >"; echo"<select name='option'>"; echo"<option value='' selected>Choices</option>"; echo"<option value='1' >1</option>"; echo"<option value='2' >2</option>"; echo"</select>"; echo"</table>"; How can grab that chosen option to print out something like this echo" ? was your choice"; Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/ Share on other sites More sharing options...
Dragen Posted May 14, 2007 Share Posted May 14, 2007 You should use a form submit, then use the $_GET() or $_POST() method. in the file it's submitted to you'd need something like: <?php $option = $_GET['option']; echo $option . "was your choice"; ?> But I get the feeling you're wanting it to display on the same page, without submitting the form. In that case you'd need to use Javascript. Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252744 Share on other sites More sharing options...
boneXXX Posted May 14, 2007 Author Share Posted May 14, 2007 Thanks a lot, I am going to use it with submitting. Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252747 Share on other sites More sharing options...
Dragen Posted May 14, 2007 Share Posted May 14, 2007 yeah, I'd suggest using $_POST over $_GET as it's more secure. Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252753 Share on other sites More sharing options...
mmarif4u Posted May 14, 2007 Share Posted May 14, 2007 $option=$_POST['option']; echo $option; Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252759 Share on other sites More sharing options...
boneXXX Posted May 14, 2007 Author Share Posted May 14, 2007 you mean something like this. Blabla.php <?php echo"<form name='form' method='post' action='./test.php'>"; echo"<table align='center' >"; echo"<select name='option'>"; echo"<option value='' selected>Choices</option>"; echo"<option value='1' >1</option>"; echo"<option value='2' >2</option>"; echo"</select>"; echo"<br><input type='submit' name='Submit' value='Send Your Choice'>"; echo"</table>"; echo"</form>"; ?> Test.php <?php $choice = $_POST['option']; echo $choice . "was your choice"; ?> Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252760 Share on other sites More sharing options...
Dragen Posted May 14, 2007 Share Posted May 14, 2007 yeah, that should work. Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252763 Share on other sites More sharing options...
mmarif4u Posted May 14, 2007 Share Posted May 14, 2007 Yes exactly... Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252764 Share on other sites More sharing options...
boneXXX Posted May 14, 2007 Author Share Posted May 14, 2007 Yes it works thanx. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/51320-select-form-php/#findComment-252769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.