Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

ok, first off this works in FF, Chrome and Safari, but does not work in IE.

  • What I am doing is converting the complex dropdown to a simple dropdown using SPServices
  • Auto-populating the projects column with a querystring parameter

Here is the code:

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>                   
    <script type="text/javascript">

    $(document).ready(function(){

        $().SPServices.SPComplexToSimpleDropdown({
            columnName: "Project"
        });    

        function getQuerystring(key, default_)
        {
          if (default_== null) default_=""; 
          key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
          var regex = new RegExp("[\\?&amp;]"+key+"=([^&amp;#]*)");
          var qs = regex.exec(unescape(window.parent.location.href));
          if(qs == null)
            return default_;
          else
            return qs[1];
        }           

        var proj = getQuerystring('proj');

        //var list = document.getElementById('ctl00_m_g_dd8909e5_25f4_49a8_b1d6_229952d5ab91_ff101_ctl00_Lookup');
        $('#ctl00_m_g_dd8909e5_25f4_49a8_b1d6_229952d5ab91_ff101_ctl00_Lookup option:contains(' + proj + ')').attr('selected', 'selected');

        if($.browser.msie){
            //var list = document.getElementById('SPComplexToSimpleDropdown_Project');

            $('#SPComplexToSimpleDropdown_Project option:contains(' + proj + ')').attr('selected', 'selected');
            var selectedVal = $('#SPComplexToSimpleDropdown_Project option:contains(' + proj + ')').val();
            alert(selectedVal);

            //set the complex dropdowns value 
            $('#ctl00_m_g_dd8909e5_25f4_49a8_b1d6_229952d5ab91_ff101_ctl00_ctl01').val(selectedVal);
        }//end if


        });
    </script>

Again, it works great, accept in IE. I know that the problem lies within assigning the value to the sharepoint complex dropdown. but now sure how to set that.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

First off, you can use $().SPServices.SPGetQueryString rather than rolling your own Query String parser. Secondly, you should be able to just set the simple select and not worry about the hidden complex select. The $().SPServices.SPComplexToSimpleDropdown function takes care of updating the complex select under the covers. Finally, you shouldn't need any different logic for IE than the other browsers.

share|improve this answer
    
would it be actually that being hidden in IE particularly is doesn't return value? –  C. Marius - MVP Apr 23 '12 at 20:21
    
It's possible that you will have to fire the change event on the simple select manually after setting it. It certainly can't hurt. –  Marc D Anderson Apr 23 '12 at 20:35
    
is there any documentation on the change event? how can I fire? –  Brenton Pierce Apr 23 '12 at 20:37
    
Have a look here api.jquery.com/trigger –  C. Marius - MVP Apr 23 '12 at 20:50
    
<select> <option value="0">One</option> <option value="1">Two</option> </select> $('select').val('1'); // selects "Two" $('select').val('Two'); // also selects "Two" Try to set the value to something fixed to make sure that the selected item is set, prior to setting it dynamically! –  C. Marius - MVP Apr 23 '12 at 21:18
show 4 more comments

Try setting the Selected using

$('#ctl00_m_g_dd8909e5_25f4_49a8_b1d6_229952d5ab91_ff101_ctl00_ctl012[value=selectedVal]').attr('selected',true);

share|improve this answer
    
This did not work –  Brenton Pierce Apr 23 '12 at 21:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.