havheg
havheg

Reputation: 89

How to use multiple select with jQuery?

I need to submit a form with multiple values

<form onsubmit="return false;">
<?php

echo "<select id=\"uname\" name=\"uname[]\" multiple>\n";

$sql = "SELECT * FROM users ORDER BY surname ASC";
$res = $db->query($sql);
while($row = $res->fetch()){
        $strA = $row["uname"];
        $strB = $row["givenname"];
        $strC = $row["surname"];
        echo "<option value=\"$strA\">$strC, $strB</option>\n";
}
echo "</select>\n";
echo "<input type='button' name='endreBruker' value='OK'   onclick='javascript:".$_POST['edit']."(this.form)'/>";
?>

and pass the POST values through this to newNote.php

function newNote(form) {
    $('#main').load ('newNote.php', {'uname[]' : form.uname.value} );
}

Problem is I only receive an array with a single value.

Upvotes: 0

Views: 341

Answers (2)

jmlnik
jmlnik

Reputation: 2887

Check out jQuery's serialize(). You could then write something like this:

function newNote(form) {
    $('#main').load ('newNote.php', $(form).serialize() );
}

Upvotes: 1

Anton Sementsov
Anton Sementsov

Reputation: 1246

You may try something like that:

<select name="theselect" onchange="this.selectedIndex = 1;">  
<option value="Red">Red</option>  
<option value="Green" selected="selected">Green</option>  
<option value="Blue">Blue</option>  
</select>

Green color always been selected, but user may see other color, but don`t pick them

Upvotes: 0

Related Questions