Page 1 of 1

problem with posting value

Posted: Wed Mar 25, 2009 3:19 pm
by dheeraj
hello guys, here i have some list boxes & i m displaying the 2nd list box on the basis of selection of 1st like below:

Code: Select all

<td><select name="type" id="s1" onchange="change_type()" style="width:180px">
      <option value="0">-- Select Property Type --</option>
      <option value="Land">Land</option>
      <option value="Residential">Residential</option>
      <option value="Commercial">Commercial</option>
    </select>
        </td>
  </tr>
  <tr>
    <td>Property Category</td>
    <td>:</td>
    <td><select name="cat" id="r" style="width:180px">
      <option value="0" selected="selected">--Property Category--</option>
      <option value="All,Residential Apartment,Independent House/Villa,Residential Land,Builder Floor">All</option>
      <option value="Residential Apartment">Residential Apartment</option>
      <option value="Independent House/Villa">Independent House/Villa</option>
      <option value="Residential Land">Residential Land</option>
      <option value="Builder Floor">Builder Floor</option>
    </select>
        <label>
        <select name="cat" id="c" style="display:none;width:180px">
          <option value="0" selected="selected">--Property Type--</option>
          <option value="All,Commercial Office Space,Commercial Shop,Commercial Showroom,Hotel,Guest House,Business Center,Warehouse/Godown,Industrial Building">All</option>
          <option value="Commercial Office Space">Commercial Office Space</option>
          <option value="Commercial Shop">Commercial Shop</option>
          <option value="Commercial Showroom">Commercial Showroom</option>
          <option value="Hotel">Hotel</option>
          <option value="Guest House">Guest House</option>
          <option value="Business Center">Business Center</option>
          <option value="Warehouse/Godown">Warehouse/Godown</option>
          <option value="Industrial Building">Industrial Building</option>
        </select>
        </label>
        <label>
        <select name="cat" id="a" style="display:none;width:180px">
          <option value="0" selected="selected">--Property Type--</option>
          <option value="All,Agricultural Land,Farm House">All</option>
          <option value="Agricultural Land">Agricultural Land</option>
          <option value="Farm House">Farm House</option>
        </select>
        </label>
Above is the list boxes, 1st list box calling a function which is used to set the style of display by using javascript below is the code...

Code: Select all

function change_type()
{
    var ind=document.getElementById("s1").value;
    if(ind == "Residential")
    {
        document.getElementById("r").style.display="";
        document.getElementById("c").style.display="none";
        document.getElementById("a").style.display="none";
    }
    
    else if(ind == "Commercial")
    {
        document.getElementById("r").style.display="none";
        document.getElementById("c").style.display="";
        document.getElementById("a").style.display="none";
    }
    
    else if(ind == "Land")
    {
        document.getElementById("r").style.display="none";
        document.getElementById("c").style.display="none";
        document.getElementById("a").style.display="";
    }   
        
}
Now the problem is that when i submit it to the next page & receive its value then every time i get value
Agricultural Land
.

i m receving value by the code

Code: Select all

<?php echo $_POST['cat'];?>

Re: problem with posting value

Posted: Wed Mar 25, 2009 3:52 pm
by requinix
You can't pass more than one value using the same name.

Use an array.

Code: Select all

<select name="cat[]"> <!-- for each one -->

Code: Select all

print_r($_POST["cat"]);