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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.