hello friends ..

i want to do one task. i want some one elp. i am new to php. when ever i check the checkbox amount will add in 'total' textbox.
i am displaying table below.

<form name="form" action="" method="post" >
<table align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my add featured $19.95 (your ad seen before free listings)
</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk1" onclick="check1()"/></td></tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad bold $4.95	
</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk2" /></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad highlighted $4.95
</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk3" /></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add Email $9.95
</td>
<td><input type="text" name="email" /></td>
<td><input type="checkbox" name="chk4" /></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add link to my website $9.95
</td>
<td><input type="text" name="link" /></td>
<td><input type="checkbox" name="chk5" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7" /></td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add larger description (up to 4,000 charters) $29.95 
</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk8" /></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7" /></td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" /></td>
</tr>
</table>
</form>

here no.of checkboxs. when ever i check one checkbox that amt willadd to total amount.
plz help me.

Recommended Answers

All 17 Replies

Found this link, and made it into this:
http://expressionengine.com/forums/viewthread/128806/

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        var total = 0;  
     
        function calcTotal() 
        { 
            $("input:checked").each(function() 
            { 
                var value = $(this).attr("value"); 
                total += parseFloat(value);  
            }); 
        } 
    
        calcTotal();     
             
        $("input:checkbox, input:radio").click(function() 
        { 
            total = 0;  
            calcTotal();  
            $("input#total").val(total);
        });
      });
    </script> 
  </head>
  <body>
    <form name="form" action="" method="post" >
      <table align="center">
        <tr>
          <td>Make my add featured $19.95 (your ad seen before free listings)</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td>Make my ad bold $4.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="4.95" /></td>
        </tr>
        <tr>
          <td>Make my ad highlighted $4.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="4.95" /></td>
        </tr>
        <tr>
          <td>Add Email $9.95</td>
          <td><input type="text" name="email" /></td>
          <td><input type="checkbox" value="9.95" /></td>
        </tr>
        <tr>
          <td>Add link to my website $9.95</td>
          <td><input type="text" name="link" /></td>
          <td><input type="checkbox" value="9.95" /></td>
        </tr>
        <tr>
          <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
          <td>or</td>
          <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Add larger description (up to 4,000 charters) $29.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="29.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
          <td>or</td>
          <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">total <input id="total" type="text" /></td>
        </tr>
      </table>
    </form>
  </body>
</html>

how to call this function from form

how to call this function from form

Copy/paste this html into test.html, open it and see what happens when you click a checkbox...

thank you so.....much for your help........mr.pritaeas. i have no words to wish. thanks a lot.

in this we can not group check boxes. so how can we select onlyone from two check boxes in the case of 'OR' case. for example checkbox1 (or)checkbox2. in this case we have to select only one checkbox. if one checkbox checked automatically other will be in uncheck.

you are looking for a radio button not a check box. Only one radio button gets selected from a defined group.
Just define each radio button in a specific group under the same "name" attribute. eg: option1 name="group1" option2 name="group1" option 3 name="group2"
above example lets you choose only 1 out of option 1 and 2 but lets u select option 3 simultaneously

in this we can not group check boxes. so how can we select onlyone from two check boxes in the case of 'OR' case. for example checkbox1 (or)checkbox2. in this case we have to select only one checkbox. if one checkbox checked automatically other will be in uncheck.

you are looking for a radio button not a check box. Only one radio button gets selected from a defined group.
Just define each radio button in a specific group under the same "name" attribute. eg: option1 name="group1" option2 name="group1" option 3 name="group2"
above example lets you choose only 1 out of option 1 and 2 but lets u select option 3 simultaneously

k. for suppse we have two checkboxes is there .we have to select one check box from that. so how can?

i think u didnt get me... checkboxes are meant for multiple selection... 1 checkbox is not supposed to be influenced by selection of other but radio buttons are meant to do so... like wen u need to select a gender u use a radio button coz u dont want both male n female to b selected..

k. for suppse we have two checkboxes is there .we have to select one check box from that. so how can?

i think u didnt get me... checkboxes are meant for multiple selection... 1 checkbox is not supposed to be influenced by selection of other but radio buttons are meant to do so... like wen u need to select a gender u use a radio button coz u dont want both male n female to b selected..

k.......i know that point. but have you see some examples like this...................."you have to select only 2choices from multiple checkboxes". there is 7 boxes is there but select 2choices only. k. got the point?

okkk now i see what u r trying to do...
u can do this easily through javascript... see this

function CountChecks() {  // call this function on onClick event of checkboxes
var maxchecked = 2;
var count = 0;
if(document.Form.check1.checked == true) { count++; }
if(document.Form.check2.checked == true) { count++; }
if(document.Form.check3.checked == true) { count++; }
if(document.Form.check4.checked == true) { count++; }
if(document.Form.check5.checked == true) { count++; }
if(document.Form.check6.checked == true) { count++; }
if(document.Form.check7.checked == true) { count++; }
if(count > maxchecked) {	
	alert('only ' + maxchecked + ' may be checked.');
	}
}

Hope this helps...

k.......i know that point. but have you see some examples like this...................."you have to select only 2choices from multiple checkboxes". there is 7 boxes is there but select 2choices only. k. got the point?

Found this link, and made it into this:
http://expressionengine.com/forums/viewthread/128806/

<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
        var total = 0;  
     
        function calcTotal() 
        { 
            $("input:checked").each(function() 
            { 
                var value = $(this).attr("value"); 
                total += parseFloat(value);  
            }); 
        } 
    
        calcTotal();     
             
        $("input:checkbox, input:radio").click(function() 
        { 
            total = 0;  
            calcTotal();  
            $("input#total").val(total);
        });
      });
    </script> 
  </head>
  <body>
    <form name="form" action="" method="post" >
      <table align="center">
        <tr>
          <td>Make my add featured $19.95 (your ad seen before free listings)</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td>Make my ad bold $4.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="4.95" /></td>
        </tr>
        <tr>
          <td>Make my ad highlighted $4.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="4.95" /></td>
        </tr>
        <tr>
          <td>Add Email $9.95</td>
          <td><input type="text" name="email" /></td>
          <td><input type="checkbox" value="9.95" /></td>
        </tr>
        <tr>
          <td>Add link to my website $9.95</td>
          <td><input type="text" name="link" /></td>
          <td><input type="checkbox" value="9.95" /></td>
        </tr>
        <tr>
          <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
          <td>or</td>
          <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Add larger description (up to 4,000 charters) $29.95</td>
          <td>&nbsp;</td>
          <td><input type="checkbox" value="29.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Add 10 key words $9.95 <input type="checkbox" value="9.95" /></td>
          <td>or</td>
          <td>Add 20 keywords $19.95 <input type="checkbox" value="19.95" /></td>
        </tr>
        <tr>
          <td><textarea name="text1" rows="6" cols="50"></textarea></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td align="right">total <input id="total" type="text" /></td>
        </tr>
      </table>
    </form>
  </body>
</html>

in the above example selected values redirecting to another page with user ids. i am putting each value in session.like this

$_SESSION['fcheckbox']=$_REQUEST['fcheckbox']

and next i have "table" in database. if particular session value
exists that column only update.
i wrote like this

if($_SESSION['fcheckbox']!='')
{
$add_update=mysql_query("UPDATE pro_listings SET featured='Y' where id=$_SESSION['add_id']   ");
}

the problem is there is 10 session values is there. among them 5 session values are null. but i want to update existing session values only ,not null values.
and also there is another solution to write update query to each session value like above. any alternative to write single line.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Total Problem Solved</title>
<script language="javascript" type="text/javascript">
function ttl()
{
 var  t=0;
  if(document.form.chk1.checked == true) {
			t=t+parseFloat(document.form.chk1.value);
} if(document.form.chk2.checked == true) {
			t=t+parseFloat(document.form.chk2.value);
}if(document.form.chk3.checked == true) {
			t=t+parseFloat(document.form.chk3.value);
}if(document.form.chk4.checked == true) {
			t=t+parseFloat(document.form.chk4.value);
}if(document.form.chk5.checked == true) {
			t=t+parseFloat(document.form.chk5.value);
}if(document.form.chk6.checked == true) {
			t=t+parseFloat(document.form.chk6.value);
}if(document.form.chk7.checked == true) {
			t=t+parseFloat(document.form.chk7.value);
}if(document.form.chk8.checked == true) {
			t=t+parseFloat(document.form.chk8.value);
}
document.form.total.value=t;}
function ch6(){if(document.form.chk6.checked == true) {
document.form.chk7.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch7(){if(document.form.chk7.checked == true) {
document.form.chk6.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch8(){if(document.form.chk8.checked == true) {
document.form.chk6.checked = false ;
document.form.chk7.checked = false;
}ttl();
}
</script>
</head>
<body>
<form name="form" action="" method="post" >
<table align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my add featured $19.95 (your ad seen before free listings)</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk1"  value="19.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad bold $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk2"  value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad highlighted $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add Email $9.95</td>
<td><input type="text" name="email" /></td>
<td><input type="checkbox" name="chk4" value="9.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add link to my website $9.95</td>
<td><input type="text" name="link" /></td>
<td><input type="checkbox" name="chk5" value="9.95" onclick="ttl()"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6"  value="9.95" onclick="ch6()"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7"  value="19.95" onclick="ch7()"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add larger description (up to 4,000 charters) $29.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk8"   value="29.95" onclick="ch8()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" disabled="disabled" /></td>
</tr>
</table>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Total Problem Solved</title>
<script language="javascript" type="text/javascript">
function ttl()
{
 var  t=0;
  if(document.form.chk1.checked == true) {
			t=t+parseFloat(document.form.chk1.value);
} if(document.form.chk2.checked == true) {
			t=t+parseFloat(document.form.chk2.value);
}if(document.form.chk3.checked == true) {
			t=t+parseFloat(document.form.chk3.value);
}if(document.form.chk4.checked == true) {
			t=t+parseFloat(document.form.chk4.value);
}if(document.form.chk5.checked == true) {
			t=t+parseFloat(document.form.chk5.value);
}if(document.form.chk6.checked == true) {
			t=t+parseFloat(document.form.chk6.value);
}if(document.form.chk7.checked == true) {
			t=t+parseFloat(document.form.chk7.value);
}if(document.form.chk8.checked == true) {
			t=t+parseFloat(document.form.chk8.value);
}
document.form.total.value=t;}
function ch6(){if(document.form.chk6.checked == true) {
document.form.chk7.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch7(){if(document.form.chk7.checked == true) {
document.form.chk6.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch8(){if(document.form.chk8.checked == true) {
document.form.chk6.checked = false ;
document.form.chk7.checked = false;
}ttl();
}
</script>
</head>
<body>
<form name="form" action="" method="post" >
<table align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my add featured $19.95 (your ad seen before free listings)</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk1"  value="19.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad bold $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk2"  value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad highlighted $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add Email $9.95</td>
<td><input type="text" name="email" /></td>
<td><input type="checkbox" name="chk4" value="9.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add link to my website $9.95</td>
<td><input type="text" name="link" /></td>
<td><input type="checkbox" name="chk5" value="9.95" onclick="ttl()"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6"  value="9.95" onclick="ch6()"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7"  value="19.95" onclick="ch7()"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add larger description (up to 4,000 charters) $29.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk8"   value="29.95" onclick="ch8()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" disabled="disabled" /></td>
</tr>
</table>
</form>
</body>
</html>

ok. fine .
after this i am redirecting to another page from this page. in there i am creating sessions to each value.

$_SESSION[chk1]=$_REQUEST[chk1];
$_SESSION[chk2]=$_REQUEST[chk2];
$_SESSION[chk3]=$_REQUEST[chk3]

like that assigning sessions to all values.
after that i will update table which is in database.
for suppose i was selected only 2 checkboxes in first page.
that fields only update without passing null values to other column values

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Total Problem Solved</title>
<script language="javascript" type="text/javascript">
function ttl()
{
 var tv="", t=0;
  if(document.form.chk1.checked == true) {
			t=t+parseFloat(document.form.chk1.value);
			tv=tv+'chk1=\''+document.form.chk1.value+'\',';
} if(document.form.chk2.checked == true) {
			t=t+parseFloat(document.form.chk2.value);
			tv=tv+'chk2=\''+document.form.chk2.value+'\',';
}if(document.form.chk3.checked == true) {
			t=t+parseFloat(document.form.chk3.value);
			tv=tv+'chk3=\''+document.form.chk3.value+'\',';
}if(document.form.chk4.checked == true) {
			t=t+parseFloat(document.form.chk4.value);
			tv=tv+'chk4=\''+document.form.chk4.value+'\',';
}if(document.form.chk5.checked == true) {
			t=t+parseFloat(document.form.chk5.value);
			tv=tv+'chk5=\''+document.form.chk5.value+'\',';
}if(document.form.chk6.checked == true) {
			t=t+parseFloat(document.form.chk6.value);
			tv=tv+'chk6=\''+document.form.chk6.value+'\',';
}if(document.form.chk7.checked == true) {
			t=t+parseFloat(document.form.chk7.value);
			tv=tv+'chk7=\''+document.form.chk7.value+'\',';
}if(document.form.chk8.checked == true) {
			t=t+parseFloat(document.form.chk8.value);
			tv=tv+'chk8=\''+document.form.chk8.value+'\',';
}
document.form.total.value=t;
document.form.query.value="update p set "+tv+"total=\'"+t+'\'';
}
function ch6(){if(document.form.chk6.checked == true) {
document.form.chk7.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch7(){if(document.form.chk7.checked == true) {
document.form.chk6.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch8(){if(document.form.chk8.checked == true) {
document.form.chk6.checked = false ;
document.form.chk7.checked = false;
}ttl();
} 
</script>
</head>
<body>
<form name="form" action='redir.php?w=' method="post" >
<table align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="text" name="query" id="query"/></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my add featured $19.95 (your ad seen before free listings)</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk1"  value="19.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad bold $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk2"  value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad highlighted $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add Email $9.95</td>
<td><input type="text" name="email" /></td>
<td><input type="checkbox" name="chk4" value="9.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add link to my website $9.95</td>
<td><input type="text" name="link" /></td>
<td><input type="checkbox" name="chk5" value="9.95" onclick="ttl()"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6"  value="9.95" onclick="ch6()"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7"  value="19.95" onclick="ch7()"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add larger description (up to 4,000 charters) $29.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk8"   value="29.95" onclick="ch8()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" disabled="disabled" /><input type="submit" value="Done" /></td>
</tr>
</table>
</form>
</body>
</html>

redir.php file

<?php
$q=stripslashes($_POST['query']);
echo "".$q;
include("config.php");
global $conn;
$result=mysql_query($q,$conn) or die("error".mysql_error());
$nm=mysql_affected_rows();
if($nm!=0)
{echo "Inserted";}else{echo "Error";}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Total Problem Solved</title>
<script language="javascript" type="text/javascript">
function ttl()
{
 var tv="", t=0;
  if(document.form.chk1.checked == true) {
			t=t+parseFloat(document.form.chk1.value);
			tv=tv+'chk1=\''+document.form.chk1.value+'\',';
} if(document.form.chk2.checked == true) {
			t=t+parseFloat(document.form.chk2.value);
			tv=tv+'chk2=\''+document.form.chk2.value+'\',';
}if(document.form.chk3.checked == true) {
			t=t+parseFloat(document.form.chk3.value);
			tv=tv+'chk3=\''+document.form.chk3.value+'\',';
}if(document.form.chk4.checked == true) {
			t=t+parseFloat(document.form.chk4.value);
			tv=tv+'chk4=\''+document.form.chk4.value+'\',';
}if(document.form.chk5.checked == true) {
			t=t+parseFloat(document.form.chk5.value);
			tv=tv+'chk5=\''+document.form.chk5.value+'\',';
}if(document.form.chk6.checked == true) {
			t=t+parseFloat(document.form.chk6.value);
			tv=tv+'chk6=\''+document.form.chk6.value+'\',';
}if(document.form.chk7.checked == true) {
			t=t+parseFloat(document.form.chk7.value);
			tv=tv+'chk7=\''+document.form.chk7.value+'\',';
}if(document.form.chk8.checked == true) {
			t=t+parseFloat(document.form.chk8.value);
			tv=tv+'chk8=\''+document.form.chk8.value+'\',';
}
document.form.total.value=t;
document.form.query.value="update p set "+tv+"total=\'"+t+'\'';
}
function ch6(){if(document.form.chk6.checked == true) {
document.form.chk7.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch7(){if(document.form.chk7.checked == true) {
document.form.chk6.checked = false ;
document.form.chk8.checked = false;
}ttl();
}
function ch8(){if(document.form.chk8.checked == true) {
document.form.chk6.checked = false ;
document.form.chk7.checked = false;
}ttl();
} 
</script>
</head>
<body>
<form name="form" action='redir.php?w=' method="post" >
<table align="center">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="text" name="query" id="query"/></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my add featured $19.95 (your ad seen before free listings)</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk1"  value="19.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad bold $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk2"  value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Make my ad highlighted $4.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add Email $9.95</td>
<td><input type="text" name="email" /></td>
<td><input type="checkbox" name="chk4" value="9.95" onclick="ttl()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add link to my website $9.95</td>
<td><input type="text" name="link" /></td>
<td><input type="checkbox" name="chk5" value="9.95" onclick="ttl()"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Add 10 key words $9.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk6"  value="9.95" onclick="ch6()"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
or</td>
<td>Add 20 keywords $19.95&nbsp;&nbsp;&nbsp;<input type="checkbox" name="chk7"  value="19.95" onclick="ch7()"/></td>
</tr>

<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
Add larger description (up to 4,000 charters) $29.95</td>
<td>&nbsp;</td>
<td><input type="checkbox" name="chk8"   value="29.95" onclick="ch8()"/></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="text1" rows="6" cols="50"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right">total &nbsp;&nbsp;&nbsp;<input name="total" type="text" disabled="disabled" /><input type="submit" value="Done" /></td>
</tr>
</table>
</form>
</body>
</html>

redir.php file

<?php
$q=stripslashes($_POST['query']);
echo "".$q;
include("config.php");
global $conn;
$result=mysql_query($q,$conn) or die("error".mysql_error());
$nm=mysql_affected_rows();
if($nm!=0)
{echo "Inserted";}else{echo "Error";}
?>

wonderful!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

document.form.query.value="update p set "+tv+"total=\'"+t+'\'';

but there is no need total.
so i wrote like this .....this is not working.

document.form.query.value="update user_registration set "+tv+'\''+"where";
var i=1;
var strLen = tv.length; 
tv = tv.slice(0,strLen-1); 
document.form.query.value="update p set "+tv+" where id=\'"+i+'\'';

where i is your id

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.