samoht Posted November 2, 2007 Share Posted November 2, 2007 hello all, I am having difficulties getting the current value of a select box to pass to a function this is what my code looks like: <?php $sql = dbQuery("SELECT PriceCode, Name FROM pricecode ORDER BY PriceCode"); $PriceRetail = $row_rsProduct['PriceRetail']; $pc = $row_rsProduct['PriceCode']; $pct = "'".$pc."'"; $Cost = $row_rsProduct['Cost']; while($row = dbFetchAssoc($sql)) { ?> <option value="<?php echo $row['PriceCode'];?>" <?php if($row['PriceCode'] == $row_rsProduct['PriceCode']){echo 'selected';}?>><?php echo $row['PriceCode']."|".$row['Name'];?></option> <?php } ?> </select></td> <td><input size="7" name="Cost" type="text" id="Cost" style="text-align:right" value="<?php echo $Cost;?>"></td> <td> <form name="calc"> <a class="calc" style="cursor:pointer" onClick="recalc_prompt(<?php echo $ProductId; ?>,<?php echo $pct; ?>)">Recalc prices</a> </form> with this code the variable $pct is only going to be the stored db value - but I need to get the select box current selection value to pass to my function - Any Ideas?? Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2007 Share Posted November 2, 2007 Your post is not clear at all. You state with this code the variable $pct is only going to be the stored db value - but I need to get the select box current selection value to pass to my function But, there is no function in the code you povided, you can't get the value of a select box selection unless you submit the form, and I don't see what $pct has to do with the problem. Quote Link to comment Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 You seem to be missing some code here 1) There is no query to retreave ... $PriceRetail = $row_rsProduct['PriceRetail']; 2) <option value="<?php echo $row['PriceCode'];?>" the <select> statment is missing Quote Link to comment Share on other sites More sharing options...
samoht Posted November 2, 2007 Author Share Posted November 2, 2007 sorry about that, the rest of the page I thought was un-needed. <select name="PriceCode" id="PriceCode" tabindex="5" style="width:180px"> is the select box code and $q = "SELECT * FROM product WHERE ProductId = '$ProductId'"; $result = dbQuery($q); $row_rsProduct = dbFetchAssoc($result); is the main query for the product info Quote Link to comment Share on other sites More sharing options...
otuatail Posted November 2, 2007 Share Posted November 2, 2007 Are you submitting this to another page or back to itself. You need at least <form action="index.php" method="post"> // or what ever page your going to and get the value of the select $val = $_POST['PriceCode']; Quote Link to comment Share on other sites More sharing options...
samoht Posted November 2, 2007 Author Share Posted November 2, 2007 actually I am passing it to a js prompt - to do a little ajax I was able to pass the current value by adding var sel = document.getElementById('PriceCode'); var selected_value = sel.options[sel.selectedIndex].value; to the prompt code and then passing selected_value - and that seems to be working ok but when I go to save it says that the PriceCode is NULL?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.