| | |
chechbox validations
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
0
#11 Nov 6th, 2009
okkk now i see what u r trying to do...
u can do this easily through javascript... see this
Hope this helps...
u can do this easily through javascript... see this
PHP Syntax (Toggle Plain Text)
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...
Last edited by venkat0904; Nov 6th, 2009 at 7:06 am.
0
#12 30 Days Ago
•
•
•
•
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>
PHP Syntax (Toggle Plain Text)
$_SESSION['fcheckbox']=$_REQUEST['fcheckbox']
exists that column only update.
i wrote like this
PHP Syntax (Toggle Plain Text)
if($_SESSION['fcheckbox']!='') { $add_update=mysql_query("UPDATE pro_listings SET featured='Y' where id=$_SESSION['add_id'] "); }
and also there is another solution to write update query to each session value like above. any alternative to write single line.
Last edited by muralikalpana; 30 Days Ago at 2:23 am.
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>
0
#14 30 Days Ago
•
•
•
•
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>
after this i am redirecting to another page from this page. in there i am creating sessions to each value.
PHP Syntax (Toggle Plain Text)
$_SESSION[chk1]=$_REQUEST[chk1]; $_SESSION[chk2]=$_REQUEST[chk2]; $_SESSION[chk3]=$_REQUEST[chk3]
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
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 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";} ?>
0
#16 29 Days Ago
•
•
•
•
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";} ?>
0
#17 29 Days Ago
PHP Syntax (Toggle Plain Text)
document.form.query.value="update p set "+tv+"total=\'"+t+'\'';
so i wrote like this .....this is not working.
PHP Syntax (Toggle Plain Text)
document.form.query.value="update user_registration set "+tv+'\''+"where";
PHP Syntax (Toggle Plain Text)
var i=1; var strLen = tv.length; tv = tv.slice(0,strLen-1); document.form.query.value="update p set "+tv+" where id=\'"+i+'\'';
![]() |
Similar Threads
- Help with Implementing email form validations please (PHP)
- validations are not working on div (JavaScript / DHTML / AJAX)
- Jsp validations (JSP)
- Validations? (JavaScript / DHTML / AJAX)
- defining objects, variables and checking validations for java (Java)
- how to implement validations for chinese characters (C#)
- jsp-struts using validations (JSP)
Other Threads in the PHP Forum
- Previous Thread: Tiles Matching Game, Sessions 1D array // random_shuffle()
- Next Thread: refresh part of the page
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert integration ip java javascript joomla ldap limit link login loop mail menu mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem provider query radio random recursion regex remote script search server sessions sms soap source space sql strip_tags structure syntax system table template tutorial update upload url validation validator variable video web xml youtube





