update variable automaticaly based on a drop down

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hopper
Forum Newbie
Posts: 5
Joined: Tue Apr 01, 2008 2:35 pm

update variable automaticaly based on a drop down

Post by hopper »

seems like a simple problem, at least to describe
i wwould like to create a simple script that has a drop down menu that when a value is chosen automaically updates the associated variable
say...
i have a drop down for.. weight, and want to use that number for calculation of body mass index
this i believe can be done with ajax
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: update variable automaticaly based on a drop down

Post by requinix »

...and I believe it can be done without PHP.

Code: Select all

<html><body>
<script type="text/javascript">
function updateLabel(value) {
    document.getElementById("label").innerHTML = "3 * " + value + " = " + (3 * value) + ".";
}
</script>
<p id="label">You haven't picked a number yet.</p>
<p><select onchange="updateLabel(this.value);">
    <option value="1">1</option>
    <option value="5">5</option>
    <option value="13">13</option>
    <option value="77">77</option>
</select></p>
</body></html>
Post Reply