[thelist] php question - changing one form value based on select choice

Alex Beston alex at deltatraffic.co.uk
Mon Oct 17 20:56:33 CDT 2005


 and heres how to do it:

<script language="javascript" type="text/javascript">
function alter(evt){
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? 
evt.srcElement : null);
        if (elem) {
                if (elem.selectedIndex > 0) {
                     var somevar = elem.options[elem.selectedIndex].value;
                    document.getElementById("product").value = somevar;
                     
                }   
        }
    }
}            
</script>

<body>
<form action="showpostedvalues.php" method="post">
<p>Category:<br>
<select onchange="alter(event);"><option value="">Choose One</option>
<option value="10 cents">red box - 10 cents    </option>
<option value="20 cents">yellow box - 20 cents</option>
<option value="30 cents">blue - 30 cents</option> </select>
</p>
<input type="hidden" name="product" value="" id="product" />
<input type="submit" />
</form>
</body>
</html>

--

showpostedvalues.php

<? print_r($_POST);
?>

hope that answers your question!
best,
Alex


More information about the thelist mailing list