0

I am new in jQuery and I am stuck in this situation:

I have a dropdown list:

 <div class="gr">
<input type="hidden" id="Referral" name="Referral" data-required="required" value="">
                                <div class="fauxSelect">
                                    <div class="arrow_btn">
                                        <div class="arrow"></div>
                                    </div>
                                    <ul class="items" data-hidden-field="Referral">
                                        <li class="item" data-value="Keith T">Keith</li>
                                        <li class="item" data-value="Steve B">Steve</li>
                                    </ul>
                                </div>
    </div>

Now, the way custom javascript code works is that whatever you select in the dropdown will be in the hidden field: Referral (this part is already done via another JS library).

Everything works fine, if I am not passing any query string param. My question is: If I am passing the link with a parameter with Keith T in it, like this:

http://application.aspx?Referral=Keith T

I want Keith to be selected in my dropdown and my dropdown should get disabled. This is what I have so far in my jQuery:

    SelectReferralFromQueryString();

    function SelectReferralFromQueryString() {
        var name = GetParameterValues('Referral');

        if (name != false) {

            name = decodeURIComponent(name);
            //here name comes correct as Keith T. What should I do from here?
        }

}
    function GetParameterValues(param) {
        var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < url.length; i++) {
            var urlparam = url[i].split('=');
            if (urlparam[0] == param) {
                return urlparam[1];
            }
            else
                return false;
        }
    }

Can someone guide me what should I do after I get the name value from Querystring?

RG-3
  • 6,088
  • 19
  • 69
  • 125
  • give some id to your dropdown e.g
      and then call $("#mydropdown").prop("disabled", true)
    – Anshul Nigam Jan 06 '15 at 03:32
  • look at this fiddle which disables dropdown if it is checked http://jsfiddle.net/tft4t/ – Anshul Nigam Jan 06 '15 at 03:34
  • @AnshulNigam: This is great for disabling the dropdown. However, my question still remains is that, I need to show the value from the querystring matching with the dropdown and then disabling it. The custom code that I have is the other way (whatever value I select in the dropdown gets added in the input field). – RG-3 Jan 06 '15 at 03:36
  • My point was that we need the css that makes your pseudo dropdown look disabled. What is .prop("disabled", true) going to do to li?? You must be using css to control this "Select list." I think you need to supply that to get your answer. – Red2678 Jan 06 '15 at 03:53
  • @AnshulNigam: Are you on https://www.codementor.io/? If you can help me and I can pay you. – RG-3 Jan 06 '15 at 04:09
  • @RG-3:Hey brother no need to pay any thing i would love to help you here,can you provide jsFiddle for what you are trying to do. – Anshul Nigam Jan 06 '15 at 04:19
  • @RG-3: I have setup a chat room for us here http://chat.stackoverflow.com/rooms/68253/room-for-anshul-nigam-and-rg-3 – Anshul Nigam Jan 06 '15 at 04:27