Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.