avis world

Let’s share my knowledge

Passing form values in an array format July 24, 2008

Filed under: Form — myworldkvs @ 6:11 am
Tags: , ,

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.

  1. 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>

  2. 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”);

    }

  3. //Receiving the passing values at PHP side
    <?
    $values = $_POST['dorm'];
    print_r($values);
    ?>

 

Leave a Reply