I wondering if any know way to change values of variable using option drop-down list ??

php script is:

<?php $searchBoxfruit = "Red"; require_once('includes/search_box.php'); ?>

and option list

<option value="Type">Type</option>
            <option value="Red">Red</option>
            <option value="Green">Green</option>
            <option value="Gray">Gray</option> 
            </select>

so basicly when user selected green option in drop down menu, $searchBoxfruit values must change to Green.

I try to fix this problem with this code:

$searchBoxfruit = "";

if (isset($_GET['0'])):  
    $searchBoxfruit = "Red";
elseif (isset($_GET['1'])):
   $searchBoxfruit = "Blue";
elseif (isset($_GET['2'])):  
    $searchBoxfruity = "White";
else:  (isset($_GET['3'])):
    $searchBoxfruit = "Black";  
endif;

php $searchBoxfruit = ""; require_once('includes/search_box.php');

but still it s does not work !!

Thanks for any hint.

Hi,

Try this :

In your page that contain the form :

<select name='color'>
    <option value="Type">Type</option>
    <option value="Red">Red</option>
    <option value="Green">Green</option>
    <option value="Gray">Gray</option> 
</select>

In your php :

// if your form method is post, use $_POST, if it's get, use $_GET
if(isset($_POST['color'])) $searchBoxfruit = $_POST['color'];

nope, not working

thanks any way

Could you put the code of the page containing the form ?

`

            <form action="test2.php" method="get">       
                <select name="categ">
                 <option value="SelectCategory">Select Category</option>
                        <option value="Red">Red</option>
                        <option value="Green">Green</option>
                        <option value="Gray">Gray</option>

                    </select>

                </form>`

You forgot to add a submit button in your form to send data.

Try this :

form.html :

<form action="test2.php" method="get">
    <select name="categ">
        <option value="SelectCategory">Select Category</option>
        <option value="Red">Red</option>
        <option value="Green">Green</option>
        <option value="Gray">Gray</option>
    </select>
    <input type='submit' />
</form>

test2.php :

<?php
    echo 'category : '.$_GET['categ'];
 ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.