Viewed   78 times

I have this HTML code :

<select name="cars">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

and to make user able to select more than one items, I'm using this jQuery plugin : http://harvesthq.github.com/chosen/

but, once it submitted... the PHP script only able to retrieve one of $_POST['cars'] value. the last one. how to make PHP to be able to retrieve ALL of it?

 Answers

3

I've found the answer...

<select name="cars[]" multiple="multiple">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

and in the PHP part :

$cars = $_POST['cars'];
print_r ($cars);
Saturday, December 3, 2022
 
fatmi
 
1
<form method="POST" action="http://the.other.server.com/script.php">
Sunday, December 11, 2022
1

There is no way how to get properties of HTML element by normal HTML behavior - but you can use JavaScript function that handles "onSubmit" form event by which you can send all you need.

Wednesday, November 16, 2022
 
3

try with as below it might be simple

 if (( isset($_GET['location']) && !empty($_GET['location']) )) {
        die(var_dump($_GET['location'])); // the var_dump doesn't return an array at all
        //$loc = implode(', ', $_GET['location']);
        $_GET['location'] = array('first'=>'loc1','second'=>'loc2','third'=>'loc3');
        $loc = implode('","', $_GET['location']);
        $loc ='"'.$loc.'"';

        $sql='SELECT  * FROM locations WHERE AreaID IN ('.$loc.')';
        echo $sql;
    }

result query

SELECT * FROM locations WHERE AreaID IN ("loc1","loc2","loc3")
Tuesday, September 20, 2022
 
jaykul
 
4

The for loop is getting one extra run. Change

for (x=0;x<=InvForm.SelBranch.length;x++)

to

for (x=0; x < InvForm.SelBranch.length; x++)
Tuesday, December 20, 2022
 
mkso
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :