locked
Get each value from multiple lookup dropdown list using JavaScript RRS feed

  • Question

  • I am able to get the values by:

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript">
            $(function () {
                //MultiLookup is filed title
                var values = $('select[title="MultiLookup selected values"]').children('option').map(function (i, e) {
                    return e.value || e.innerText;
                }).get();
                alert(values);
            })
        </script>

    But I really need to loop through each value and pass it to a function.

    Any help would be great.

    Wednesday, November 20, 2019 2:22 AM

Answers

  • Hi developer sp,

    I understand you want to get each value in the multiple lookup column selected dropbox in list form like below:

    I tested you code snippet above, it will return an array with selected option values:

    If you want each value instead of array, modify like this:

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript">
            $(function () {
                //MultiLookup is filed title
                var text = $('select[title="Employee Boundary-Component selected values"]').children('option').toArray().map(item => item.text).join();
                var value= $('select[title="Employee Boundary-Component selected values"]').children('option').toArray().map(item => item.value).join();
                console.log(text);
                console.log(value);                        
            })
        </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, November 20, 2019 8:52 AM

All replies

  • Below JavaScript will get you all the Selected values from the drop down list.

    <!DOCTYPE html>
    <html>
    	<head>
    		<title>JavaScript - Get selected value from dropdown list</title>
    	</head>
    
    	<body>
    
    		<h1>JavaScript - Get selected value from dropdown list</h1>
    
    		<p id="result">United State</p>
    		
    		<select id="country">
    			<option value="None">-- Select --</option>
    			<option value="ID001">China</option>
    			<option value="ID002" selected>United State</option>
    			<option value="ID003">Malaysia</option>
    		</select>
    
    		<script>
    
    			function GetSelectedValue(){
    				var e = document.getElementById("country");
    				var result = e.options[e.selectedIndex].value;
    				
    				document.getElementById("result").innerHTML = result;
    			}
    
    			function GetSelectedText(){
    				var e = document.getElementById("country");
    				var result = e.options[e.selectedIndex].text;
    				
    				document.getElementById("result").innerHTML = result;
    			}
    			
    		</script>
    
    		<br/>
    		<br/>
    		<button type="button" onclick="GetSelectedValue()">Get Selected Value</button>
    
    		<button type="button" onclick="GetSelectedText()">Get Selected Text</button>
    	</body>
    
    </html>

    Below articles for your reference:

    https://www.mkyong.com/javascript/javascript-get-selected-value-from-dropdown-list/

    https://stackoverflow.com/questions/5866169/how-to-get-all-selected-values-of-a-multiple-select-box/39363742

    Thanks & Regards,


    sharath aluri

    Wednesday, November 20, 2019 2:43 AM
  • Hi developer sp,

    I understand you want to get each value in the multiple lookup column selected dropbox in list form like below:

    I tested you code snippet above, it will return an array with selected option values:

    If you want each value instead of array, modify like this:

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript">
            $(function () {
                //MultiLookup is filed title
                var text = $('select[title="Employee Boundary-Component selected values"]').children('option').toArray().map(item => item.text).join();
                var value= $('select[title="Employee Boundary-Component selected values"]').children('option').toArray().map(item => item.value).join();
                console.log(text);
                console.log(value);                        
            })
        </script>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, November 20, 2019 8:52 AM
  • Hi Jerry:

    Thanks for your help.

    Friday, November 22, 2019 12:33 PM