Click here to Skip to main content
16,011,743 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi

i have select box with options as

<div class="sortvalue">

<span>Sort By : </span>

<select id="ddlCountry" runat="server" onchange="GetCountryDetails()">
<option id="sortval" value="" ></option>
<option id="sortvalltoh" value="ltoh" >Rating Low to High</option>
<option id="sortvalhtol" value="htol" >Rating High to Low</option>
<option id="sortvalPrfd" value="Prfd" >Preferred</option>
</select>
</div>

and i reload the page again with option selected value.

ie. if i select value high to low,  i reload page with attached "&test=ltoh"  in querystring .

and then  i want to make that option as selected from jquery after loading page ,

how is this possible

regards

maulik shah
Posted

1 solution

Hi Mauli,

Below function is used to read the query string from URL and map the value to ddl option

This can be used in document.ready() function like
JavaScript
$(document.ready(function() {
 var qs = (function(a) {
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i)
    {
        var p=a[i].split('=');
        if (p.length != 2) continue;
        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
})(window.location.search.substr(1).split('&'));

if(qs['test'] !=  undefined){
    $('#ddlCountry').val(qs['test']);
 }
}));


Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
v5
Comments
maulikshah1990 22-Nov-13 7:21am    
where to call assignDDL() function from
♥…ЯҠ…♥ 22-Nov-13 7:27am    
Updated my solution, no need to call the function, you can paste it in script section as it is and try to execute... tell me what you see
maulikshah1990 22-Nov-13 7:37am    
thanks..that worked...
♥…ЯҠ…♥ 22-Nov-13 7:40am    
Then Please accept it as solution which might help someone,I think the solution deserves vote.... ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900