Getting selected item from complex dropdown list

Oct 21, 2011 at 12:05 PM

I am reletively new to jQuery and having trouble getting the selected option in a list of more than 20 items in sharepoint, The code below works for lists of 20 or less but not for lists of greater than 20. If any one has a snipet of code that will enable me to set a variable with the selected value from a complex dropdown it would be greatly appreciated.

 

  1. <script language="javascript" src="//jquery-1.6.4.js" type="text/javascript"></script> <script language="javascript" src="//jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
     
    var sProcess ="";
    $(document).ready(function() {
    $("select[title$='Process']").change(function(){
     sProcess = $("select[title$='Process'] option:selected ").text()
    });
    });</script>
Coordinator
Oct 21, 2011 at 12:23 PM
Dave:

If you look at the code for SPCascadeDropdowns or SPDisplayRelatedInfo, you'll see how I find the selected values. If that doesn't get you there, post back.

M.
Oct 21, 2011 at 5:20 PM
sympmarc wrote:
Dave:

If you look at the code for SPCascadeDropdowns or SPDisplayRelatedInfo, you'll see how I find the selected values. If that doesn't get you there, post back.

M.


Marc

Thanks for you quick response, as I said I am reletily new to all this. I had a look at the code for both Cascade & Related and after a number of hours of trail and error. I have failed to find the answer. I know this is down to my  lack of knowledge, but any help would be greatly appreciated

 

Dave

Coordinator
Oct 21, 2011 at 5:32 PM

Dave:

Try grabbing:

$("input[Title='" + colName + "']")).attr("value")

M.

Oct 21, 2011 at 7:22 PM

Marc

      Thanks again for the prompt reply. That works great for grabbing the value, the issue now is how to envoke setting the 'var' since the .change does not fire.

 

$("unit[title$='Process']").change(function(){
         sProcess = $("input[title$='Process']").attr("value")
         });

 

 

Thanks

Coordinator
Oct 21, 2011 at 7:40 PM

I call it "complex" for a reason. ;+)

Here's what I do:

   case "C":
    parentSelect.Obj.bind("propertychange", function() {
     cascadeDropdown(opt, childSelect);
    });
    // Fire the change to set the allowable values
    parentSelect.Obj.trigger("propertychange");
    break;

Then I check to see if the value has actually changed. There are multiple user actions that can change it.

M.

 

Oct 23, 2011 at 1:01 AM

Marc

Thanks for your help in resolving this, I have at last got it to work.

code below

$("input[title='Process']").bind("propertychange", function( {              
                sProcess = $("input[title$='Process']").attr("value")               
       });
Once again thanks for your help
Dave
Coordinator
Oct 23, 2011 at 3:54 AM

Sure thing, Dave. You sghould improve the efficiency a little if you do this:

$("input[title='Process']").bind("propertychange", function( {              
  sProcess = $(this).attr("value");
});

Be aure to use terminating semi-colons, too.

M.