Welcome to Dream.In.Code
Click Here
Getting PHP Help is Easy!

Join 117,274 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,935 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Dynamically update php variables based on option value

 
Reply to this topicStart new topic

Dynamically update php variables based on option value

Hrimthurs
post 6 May, 2008 - 10:00 AM
Post #1


New D.I.C Head

*
Joined: 10 Jan, 2008
Posts: 1

Hi there,
This is a little hard to explain, but i'll give it a go.
What i need to do is have a <select> dropdown with options, eg.
CODE
<select name="finish">
<option  value="" selected="selected">Select a finish</option>
<option value="white">White</option>
<option value="black">Black</option>
</select>

Of which, the selected option is called in as a variable via php and echoed later on in the same page, which dynamically updates when you select a different option.
I thought the code would look something like this
CODE
<?php echo $_GET['finish'];  
echo $finish; ?>

But that method won't update dynamically.
Is anyone able to help?
User is offlineProfile CardPM

Go to the top of the page


mocker
post 6 May, 2008 - 10:54 AM
Post #2


D.I.C Head

**
Joined: 14 Oct, 2007
Posts: 219



Thanked 11 times
My Contributions


If you want something on the page to update when you select a different option, you'll have to set some javascript to trigger. You can either have the javascript submit the form as soon as the select value is changed, then have php read in the value and update what you need, or you could have php write out a bunch of javascript variables, and have javascript change the page.

ie..
output the javascript variables
CODE

echo 'var values[1] = "you selected 1"; ';
echo 'var values[2] = "you selected 2"; ';

echo 'function updateDiv( var_id){
         document.someDiv.innerHTML = values[var_id];
}';


and your select box
CODE

<form name="form1">
<select name="finish" onChange="updateDiv(document.form1.finish.selectedIndex);">
...etc


of course you'll probably have you php coding loading the ids and options from some data source
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/6/08 10:30PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month