Jump to content

Select Form - PHP


boneXXX

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.