Jump to content

Retrive Checkbox


alwaysvaghu
 Share

Recommended Posts

Hi...How to retrieve checkbox info using php..Here is the code<html><body><script language="javascript"> function Validate4( ) { var Lform = this.document.form4; boxes = Lform.info.length txt = "" for (i = 0; i < boxes; i++) { if (Lform.info.checked) { txt = txt + Lform.info.value + " " } } if (txt == "") { alert("No textbox ticked"); return false; } return true; }</script><form name=form action="sendinq.php" method=post onSubmit="return validate()">Info Needed  : <input type=checkbox name="info" value="HC11">HC11<br> <input type=checkbox name="info" value="HC12">HC12<br> <input type=checkbox name="info" value="8051">8051<br> <input type=checkbox name="info" value="8086">80X86<br> <input type=checkbox name="info" value="PIC">PIC<br> <input type=checkbox name="info" value="DSP">DSP</form></body></html>

Link to comment
Share on other sites

The posted fields are an array, you declare them in the(html) form as name="info[]".You also have to adjust the way you reference these in your javascript validation.

<html><head><script type="text/javascript">function Validate4( ){var Lform = document.forms['form4'];var info = Lform.elements['info[]'];var boxes = info.length;var txt = "";for (i = 0; i < boxes; i++){  if(info[i].checked)  {    txt = txt + info[i].value + " ";  }}if(txt == ''){alert("No textbox ticked");return false;}return true;}</script></head><body><?phpif(isset($_POST['info'])){  $boxArray = $_POST['info'];  echo "You checked the following:<br>";  foreach($boxArray as $x => $val){      echo "$val<br>";  }}?><form name="form4" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onSubmit="return Validate4()">Info Needed  :<br><input type=checkbox name="info[]" value="HC11">HC11<br><input type=checkbox name="info[]" value="HC12">HC12<br><input type=checkbox name="info[]" value="8051">8051<br><input type=checkbox name="info[]" value="8086">80X86<br><input type=checkbox name="info[]" value="PIC">PIC<br><input type=checkbox name="info[]" value="DSP">DSP<input type="submit"></form></body></html>

Thanks,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...