Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Calculation with Radio buttons
Old 02-05-2010, 01:47 PM Calculation with Radio buttons
Junior Talker

Posts: 1
Name: Faisal
Trades: 0
Hi, i am having a problem here with PHP (Brand new in this area ). See my form below:

http://docs.google.com/leaf?id=0B4oe...OTg3OThk&hl=en


What i am trying to do is,

a) For Play_1, user will choose First or Second. If the user choose First then on the right side into the textarea (first row, last column) automatically value 10 will appear. Or if the user choose second then on the right side into the textarea (first row, last column) automatically value 5 will appear.

b) For Play_2, it will work just like Play_1

c) Finally, the code will get the main two values of Play_1 and Play_2 (last column, two rows), sum them up and present the Total in the Total textarea.

The code i have written is as follows, which is for sure not running:

PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
  <table width="266" border="1">
    <tr>
      <td width="49">Play_1</td>
      <td width="61">First 
      <input name="radiobutton" type="radio" value='10'></td>    
    
      <td width="92">Second 
      <input name="radiobutton" type="radio" value='5'></td>  
      
      <?php
        $selected_radio 
$_POST['radiobutton'];
            if(
$selected_radio == 10) {
                
$v1=10;
            }
            else if (
$selected_radio == 5) {
                
$v1=5;
            }
     
?>
      
      <td width="36"><input name="textarea" type="text" value= "<?php echo $v1?>" size="5"></td>
    </tr>
    <tr>
      <td>Play_2</td>
      <td>First 
      <input name="radiobutton1" type="radio" value="10"></td>
      <td>Second 
      <input name="radiobutton1" type="radio" value="5"></td>
      
      <?php
        $selected_radio 
$_POST['radiobutton1'];
            if(
$selected_radio == 10) {
                
$v2=10;
            }
            else if (
$selected_radio == 5) {
                
$v2=5;
            }
     
?>
     
      <td><input name="textarea2" type="text" value="<?php echo $v2?>" size="5"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>Total : </td>
      <td><input name="textarea3" type="text" value="<?php echo $v1+$v2?>" size="5"></td>
    </tr>
  </table>
  
 
</form>
</body>
</html>
Can anyone please guide me? Thanks in advance
faisalnet5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-09-2010, 08:19 AM Re: Calculation with Radio buttons
Experienced Talker

Posts: 41
Name: Adam B
Trades: 0
Are $v1 and $v2 correct when you display them individually?

Try a print_r() on the $_POST array to check the names/values are as you expect. If still no luck try debugging the variables by echoing out the value after each significant part of the code.
adam89 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Calculation with Radio buttons
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10235 seconds with 12 queries