Jump to content

get a value from select box


samoht

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/75787-get-a-value-from-select-box/
Share on other sites

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.

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

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??

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.