I have a form:
you can do it like this:
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(){
$("#go").click(function(){
var g = $("#genres").val();
var href = 'results.php?genres=';
if(g != null) {
href += g;
}
document.location.href=href;
});
});
</script>
</head>
<body>
<select id="genres" size="3" multiple>
<option value="jazz">jazz</option>
<option value="blues">blues</option>
<option value="rock">rock</option>
</select>
<input type="button" value="go" name="submit" id="go">
</body>
</html>
in results.php you should:
$g = isset($_GET['genres'])?$_GET['genres']:"";
$genres = explode(",",$g);
i have removed the form completely because the genres are now sent by document.location.href
. The .val()
function of jquery returns the selected values like expected (imploded by ,
)