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 !!

0

4 Answers 4

2

Php is always interpreted before sending content to client. HTML is part of that content. Once you get to see HTML elements, such as your dropdown list, you can't tell PHP to modify an exisiting variable.

The best thing to do is to use a form whichs sends GET or POST data to a php page.

Sign up to request clarification or add additional context in comments.

Comments

0

Thats the quite basic part of form processing. Like,

If your "<select>" is named fruit and the form is submitted.

$_POST['fruit'] shall give the value.

1 Comment

Thanks, but can you provide more deatlis?
0


<?php
<form action="" method="post" id="kid">
<select name="op">
<option value="Pink">Pink</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Gray">Gray</option>
</select>


<input type="submit" value="SUBMIT" name='but'>
</form>
<?php
<br>if( $_POST ) <br>{ <br> var_dump( $_POST );
<br>} <br>



?>

I think u should study this code a bit

Comments

-1

This can't be done with purely HTML/PHP.

You could trigger a form post when the users selects another option, or, better yet, do an AJAX call to set the variable.

But why would you want to do it real time?

Just get the value when the form is submitted in the $_POST['nameofyoucontrol'] variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.