Form input array $_GET comma separated in URL

旧街凉风 提交于 2019-12-02 07:11:41

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 ,)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!