Page 1 of 1

update variable automaticaly based on a drop down

Posted: Tue Oct 21, 2008 5:17 pm
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

Re: update variable automaticaly based on a drop down

Posted: Tue Oct 21, 2008 7:08 pm
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>