Jump to content

Radio Buttons


LearningKid

Recommended Posts

Hey im not sure how to do this, I have a page tht calculates cost for something, now i want to add radio buttons so tht if someone has to print something price can increase as ppl select the buttons, default will be ur printin B&W and the options wud be Color, or Single Side Printing or Double side.

 

this is what i have so far.


<?php 
$quantity = $_POST['pages'];

// set original and current unit price
// LIKE HERE THE DEFAULT PRICE WUD BE $20 AND IF ITS COLOR THE PRICE CHANGES TO $22

$origPrice = 20;
$currPrice = $origPrice * $quantity;

// calculate difference in price
$tax = 16;

// calculate percentage change in price
$PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0);

?>

 

Any hlp wud be appreciated Thank You

Link to comment
Share on other sites

you're going to need to give us more than that. have you written the radio button element into the form yet? if so, what values are you expecting the form to return on submission? and how do you want the price to be calculated - is it just a static add-on to the price of the item?

Link to comment
Share on other sites

you're going to need to give us more than that. have you written the radio button element into the form yet? if so, what values are you expecting the form to return on submission? and how do you want the price to be calculated - is it just a static add-on to the price of the item?

 

Im getting the Info give me a few mins

Link to comment
Share on other sites

something like this but without the submit button i want when i selct a radio button it automatically updates the price to wat i selected and keep the radio button cheked.

Thank You hope this will hlp

<html>
<body>
<form action="count.php" method="post">
  B&W <input type="radio" name="bw/c" value="1" /><br />
  Color <input type="radio" name="bw/c" value="2"  /><br />
  <input type="submit" value="submit" />
</form>
<?php

require_once ('includes.php');
// set quantity

$quantity = 4;

$answer = $_POST['bw/c'];

    if ($answer == "2") {
        
        $origPrice = 22;
        
    }
    
    else {
       
       
// set original and current unit price

$origPrice = 20;
}
$currPrice = $origPrice * $quantity;

// calculate difference in price
$tax = 16;

// calculate percentage change in price
$PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0);

?>

<table border="1" cellpadding="5" cellspacing="0" >
<tr>
<td>Quantity</td>
<td>Cost price Per Page</td>
<td>Current price Without Vat</td>
<td>Vat</td>
<td>Total Cost With Vat</td>
</tr>
<tr align="center">
<td><?php echo $quantity; ?></td>
<td>$<?php echo $origPrice; ?></td>
<td>$<?php echo $currPrice; ?></td>
<td><?php echo $tax; ?>%</td>
<td>$<?php echo $PriceTaxed; ?></td>
</tr>
</table>
<br /><br /><a href="logout.php">leave</a>

</body>
</html> 

Link to comment
Share on other sites

.. and is that script currently not working? you will only get the value of the radio button once the form has been submitted. are you receiving errors? one thing i might point out is that i'm not sure you can use slashes in the name of the input.

 

if you want it to stay checked after submitting the form, this is merely a matter of checking whether the POSTed value matches that of the radio button when you're echoing it:

 

<input type="radio" name="colour_print" value="1"<?php if (isset($_POST['colour_print']) && $_POST['colour_print'] == '1') echo ' checked="true"'; ?> />

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.