Jump to content

Radio button values problem


Scooby08

Recommended Posts

Im having a problem figuring this one out, and I am out of ideas..

 

I have this code:

 

<table>
    <tr><th>Wedding Packages</th><th>Choose One</th><th>Unit Price</th><th>Cost</th></tr>
<?php 
    $query_wp = "SELECT item_id, item_description, item_price FROM dw_items WHERE item_category = 'wedding_packages'";
    $result_wp = mysql_query($query_wp) or die(mysql_error());
    while($row_wp = mysql_fetch_array($result_wp)) { 
    ?>	
    <tr>
        <td><?=$row_wp['item_description'];?></td>
        <td><input type="radio" name="item_id_wp" value="<?=$row_wd['item_id'];?>" id="qty_item_1" /></td>
        <td id="price_item_1">15.99</td>
        <td id="total_item_1"></td> 
    </tr> 
    <?php } ?>
</table>

 

It pulls the data from the database and displays multiple rows of radio buttons.. Works out great for me.. Here is the problem.. I need to figure out a way to get the value of each radio input to equal 1 if clicked and 0 if unclicked.. But also I am using the value to send which item was checked to the database, so as right now the value is whatever it pulls from the database.. The reason I need the value to equal 1 when checked is because each input has a dollar amt value and I am using the jquery calculation plugin which relies on each value to calculate the total.. I hope somebody can understand this..

 

I have tried adding this to the end of each input and it almost does what is needed..

 

onclick="this.value = 1;" onblur="this.value = <?=$row_wp['item_id_wp'];?>;"

 

The value is set to 1 for the calculation, and then the onblur is the value I wish to send to the database.. Problem is when the onblur takes effect the calculation is thrown off with the original value and the total is then incorrect again.. 

 

Guess Im looking for the ultimate answer here..

Link to comment
Share on other sites

I beleive your problem is here;

<td><input type="radio" name="item_id_wp" value="<?=$row_wd['item_id'];?>" id="qty_item_1" /></td>

 

It should be

<td><input type="radio" name="item_id_wp" value="<? $row_wd['item_id'];  ?>" id="qty_item_1" /></td>

 

Basickly you have an extra = sign you do not need.

Link to comment
Share on other sites

Hey guys.. Thanks for the reply!!

 

I see what you are saying, but I need a value in there.. The = sign is just used to echo the value and it works just fine..

 

The problem is beyond that.. What you see there works just fine for entering data into the database.. Its the calculation that is getting screwed up with this..

 

Here is a quick example of what's going on here..

 

<input type="radio" name="item_id_wp" value="1" id="qty_item_1" />
<input type="radio" name="item_id_wp" value="2" id="qty_item_1" />
<input type="radio" name="item_id_wp" value="3" id="qty_item_1" />

 

Now there the value is just called from the database, but the jquery calculation plugin I am using uses that value to multiply the value... So those lines would be like so:

 

<input type="radio" name="item_id_wp" value="1" id="qty_item_1" /> (1 * $10.00) = $10.00
<input type="radio" name="item_id_wp" value="2" id="qty_item_1" /> (2 * $10.00) = $20.00
<input type="radio" name="item_id_wp" value="3" id="qty_item_1" /> (3 * $10.00) = $30.00

 

when I need them to be like so:

 

<input type="radio" name="item_id_wp" value="1" id="qty_item_1" /> (1 * $10.00) = $10.00
<input type="radio" name="item_id_wp" value="2" id="qty_item_1" /> (1 * $10.00) = $10.00
<input type="radio" name="item_id_wp" value="3" id="qty_item_1" /> (1 * $10.00) = $10.00

 

but still send the original called values to the database with their choice of which radio button was checked..

 

Im sorry it's so confusing, but I have no where else to go for help.. Thank you..

 

Can I post example links on here without problem?

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.