0

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.

2
Contributors
5
Replies
15
Views
5 Years
Discussion Span
Last Post by akmozo
0

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'];

Edited by akmozo

0

`

            <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>`
0

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'];
 ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.