开发者

unable to set values of select tag in jquery mobile

I had created a select tag in html(SelectTest.html) with some values.What i'm trying to do is after selecting any value from select tag, i need the page to be refreshed and pass the selected option as parameter to url.

Then i need to set this as selected value once the page is refreshed. I'm not sure whether this problem is related to jQuery mobile.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobi开发者_运维知识库le-1.0a3.min.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script> 
<script type="text/javascript">
$(document).ready(function(){

    var param = window.location.search;

    if(param)
    {


      var indx = param.indexOf("=");

        //now get the value of selected type

        aval =param.substring(indx+1);

        $("#lang").val(aval);
    }   

    $("#lang").change(function(){

        var sel = $(this).val();


         window.location.href="SelectTest.html?type="+sel;

        });

});



</script>
<title>Insert title here</title>
</head>
<body>
<div data-role="page" id="home" data-theme="e"> 
<div data-role="header"> 
<h1>Test</h1> 
</div>
<div data-role="content" id="toi">

<div>
<label for="lang">Select Language</label>
<select name="language" id="lang">
<option value="en">English</option>
<option value="hi">Hindi</option>
<option value="sp">Spanish</option>
<option value="fr">French</option>
</select>
</div>



<div id="main">

</div>
</div>
</div> 
<div data-role="footer"> 
<h4>Test</h4> 
</div> 
</div>
</body>
</html>


From the jquery mobile docs:

If you manipulate a select via JavaScript, you must call the refresh method on it to update the visual styling. Here is an example:

var myselect = $("select#foo");
myselect[0].selectedIndex = 3;
myselect.selectmenu("refresh");

So basically you just need to call refresh on it. Does this help?

For your code you can chain it like this

$('#lang').val(aval).selectmenu("refresh");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜