Here is the code that you shall pass the form values in an array format. The name with [] that identify is an array. At the php side, just mention $_POST['dorm'] to receive the parameter values posted from Form.
- Html Code:
<form name=”myform” method=”post” onsubmit=”check()”>
<input type=”text” name=”dorm[]“>
<input type=”text” name=”dorm[]“>
<input type=”text” name=”dorm[]“>
<input type=”text” name=”dorm[]“>
<input type=”text” name=”dorm[]“>
<input type=”text” name=”dorm[]“>
<input type=”submit” name=”submit” value=”S”>
</form> - Javascript Validation:
function check_All()
{
var form = document.myform.elements;
for(var i=0;i<form.length;i++)
{
// alert(form[i].name);
}
}
function check_particular()
{
var txtbox = document.myform.elements['dorm[]‘]; // Returns the node list; node list stored as an array;
// Find an length
var len = txtbox.length
// Retrive the value
if (txtbox[0].value==”")
alert(” Mandatory to fill up the first field”);}
- //Receiving the passing values at PHP side
<?
$values = $_POST['dorm'];
print_r($values);
?>