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.'); } }
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/
PHP Syntax (Toggle Plain Text)
<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> </td> <td><input type="checkbox" value="19.95" /></td> </tr> <tr> <td>Make my ad bold $4.95</td> <td> </td> <td><input type="checkbox" value="4.95" /></td> </tr> <tr> <td>Make my ad highlighted $4.95</td> <td> </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> </td> <td> </td> </tr> <tr> <td>Add larger description (up to 4,000 charters) $29.95</td> <td> </td> <td><input type="checkbox" value="29.95" /></td> </tr> <tr> <td><textarea name="text1" rows="6" cols="50"></textarea></td> <td> </td> <td> </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> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td align="right">total <input id="total" type="text" /></td> </tr> </table> </form> </body> </html>
$_SESSION['fcheckbox']=$_REQUEST['fcheckbox']
if($_SESSION['fcheckbox']!='') { $add_update=mysql_query("UPDATE pro_listings SET featured='Y' where id=$_SESSION['add_id'] "); }
<!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> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> Make my add featured $19.95 (your ad seen before free listings)</td> <td> </td> <td><input type="checkbox" name="chk1" value="19.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad bold $4.95</td> <td> </td> <td><input type="checkbox" name="chk2" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad highlighted $4.95</td> <td> </td> <td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </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> </td> <td> </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> </td> <td> </td> </tr> <tr> <td>Add 10 key words $9.95 <input type="checkbox" name="chk6" value="9.95" onclick="ch6()"/> or</td> <td>Add 20 keywords $19.95 <input type="checkbox" name="chk7" value="19.95" onclick="ch7()"/></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Add larger description (up to 4,000 charters) $29.95</td> <td> </td> <td><input type="checkbox" name="chk8" value="29.95" onclick="ch8()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><textarea name="text1" rows="6" cols="50"></textarea></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right">total <input name="total" type="text" disabled="disabled" /></td> </tr> </table> </form> </body> </html>
PHP Syntax (Toggle Plain Text)
<!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> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> Make my add featured $19.95 (your ad seen before free listings)</td> <td> </td> <td><input type="checkbox" name="chk1" value="19.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad bold $4.95</td> <td> </td> <td><input type="checkbox" name="chk2" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad highlighted $4.95</td> <td> </td> <td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </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> </td> <td> </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> </td> <td> </td> </tr> <tr> <td>Add 10 key words $9.95 <input type="checkbox" name="chk6" value="9.95" onclick="ch6()"/> or</td> <td>Add 20 keywords $19.95 <input type="checkbox" name="chk7" value="19.95" onclick="ch7()"/></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Add larger description (up to 4,000 charters) $29.95</td> <td> </td> <td><input type="checkbox" name="chk8" value="29.95" onclick="ch8()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><textarea name="text1" rows="6" cols="50"></textarea></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right">total <input name="total" type="text" disabled="disabled" /></td> </tr> </table> </form> </body> </html>
$_SESSION[chk1]=$_REQUEST[chk1]; $_SESSION[chk2]=$_REQUEST[chk2]; $_SESSION[chk3]=$_REQUEST[chk3]
<!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> </td> </tr> <tr> <td><input type="text" name="query" id="query"/></td> </tr> <tr> <td> </td> </tr> <tr> <td> Make my add featured $19.95 (your ad seen before free listings)</td> <td> </td> <td><input type="checkbox" name="chk1" value="19.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad bold $4.95</td> <td> </td> <td><input type="checkbox" name="chk2" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad highlighted $4.95</td> <td> </td> <td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </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> </td> <td> </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> </td> <td> </td> </tr> <tr> <td>Add 10 key words $9.95 <input type="checkbox" name="chk6" value="9.95" onclick="ch6()"/> or</td> <td>Add 20 keywords $19.95 <input type="checkbox" name="chk7" value="19.95" onclick="ch7()"/></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Add larger description (up to 4,000 charters) $29.95</td> <td> </td> <td><input type="checkbox" name="chk8" value="29.95" onclick="ch8()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><textarea name="text1" rows="6" cols="50"></textarea></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right">total <input name="total" type="text" disabled="disabled" /><input type="submit" value="Done" /></td> </tr> </table> </form> </body> </html>
<?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";} ?>
redir.php filePHP Syntax (Toggle Plain Text)
<!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> </td> </tr> <tr> <td><input type="text" name="query" id="query"/></td> </tr> <tr> <td> </td> </tr> <tr> <td> Make my add featured $19.95 (your ad seen before free listings)</td> <td> </td> <td><input type="checkbox" name="chk1" value="19.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad bold $4.95</td> <td> </td> <td><input type="checkbox" name="chk2" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Make my ad highlighted $4.95</td> <td> </td> <td><input type="checkbox" name="chk3" value="4.95" onclick="ttl()"/></td></tr> <tr> <td> </td> <td> </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> </td> <td> </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> </td> <td> </td> </tr> <tr> <td>Add 10 key words $9.95 <input type="checkbox" name="chk6" value="9.95" onclick="ch6()"/> or</td> <td>Add 20 keywords $19.95 <input type="checkbox" name="chk7" value="19.95" onclick="ch7()"/></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> Add larger description (up to 4,000 charters) $29.95</td> <td> </td> <td><input type="checkbox" name="chk8" value="29.95" onclick="ch8()"/></td></tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><textarea name="text1" rows="6" cols="50"></textarea></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td align="right">total <input name="total" type="text" disabled="disabled" /><input type="submit" value="Done" /></td> </tr> </table> </form> </body> </html>
PHP Syntax (Toggle Plain Text)
<?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";} ?>
document.form.query.value="update p set "+tv+"total=\'"+t+'\'';
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+'\'';
| DaniWeb Message | |
| Cancel Changes | |