ppbb123 Posted June 10, 2013 Report Share Posted June 10, 2013 Hi, I found the link how to select multiple values from a listbox in a WebForm, but how about the Update Form or Details page? Thanks Quote Link to comment Share on other sites More sharing options...
0 MayMusic Posted June 10, 2013 Report Share Posted June 10, 2013 Try this: <script> function select_ (){ // get listbox element var listbox = document.getElementById("EditRecordFIELD"); // get listbox length var len = listbox.options.length; // get selected element var selected = listbox.options[len-1].value; // verify if selected element contains comas, if yes, do the following if (selected.indexOf(",") != -1 ){ // Split selected option into array var m_array = new Array();m_array=selected.split (","); // Delete last option from the listbox listbox.options.remove(len-1); // Go through listbox and select each option, if it is present in array for( var i=0; i< m_array.length; i++ ){for( var j=0; j< len-1; j++ ){ // Trim spaces while comparing elements from array and listbox if( m_array[i].replace(/^s+|s+$/g, ') == listbox.options[j].value ){ listbox.options[j].selected = "selected"; }}}}} // Enable multiselect for listboxdocument.getElementById("EditRecordFIELD").multiple="multiple"; // call select_ funtion when details page is loaded window.onload = select_; </script> Replace FIELD in "EditRecordFIELD" with the actual field name. Quote Link to comment Share on other sites More sharing options...
0 MayMusic Posted June 28, 2013 Report Share Posted June 28, 2013 If you have more than one listboxes on your details or update user this code <script> // Function for selecting corresponding elements from the list box. function select_ (){ // get listbox element var o_els = new Array("EditRecordFIELDNAME","EditRecordFIELDNAME2","EditRecordFIELDNAME3"); for (var k=0; k< o_els.length; k++ ) { var o_el = document.getElementById(o_els[k]); // Enable multiselect for listbox o_el.multiple="multiple"; // get listbox length var len = o_el.options.length; // get selected element var selected = o_el.options[len-1].value; // verify if selected element contains comas, if yes, do the following if (selected.indexOf(",") != -1 ){ // Split selected option into array var m_array = new Array();m_array=selected.split (","); // Delete last option from the listbox o_el.options.remove(len-1); // Go through listbox and select each option, if it is present in array for( var i=0; i< m_array.length; i++ ){for( var j=0; j< len-1; j++ ){ // Trim spaces while comparing elements from array and listbox if( m_array[i].replace(/^s+|s+$/g, '') == o_el.options[j].value ){ o_el.options[j].selected = "selected"; } } } } } } // call select_ funtion when details page is loaded window.onload = select_; </script> karikounkel and TWIRED 2 Quote Link to comment Share on other sites More sharing options...
0 TWIRED Posted January 14, 2017 Report Share Posted January 14, 2017 Got it to work. Thanks to May for for this script. There was a couple of small syntax error Double quotes was missing in script if( m_array.replace(/^s+|s+$/g, "") == listbox.options[j].value ){ Space after, comma was missing while splitting array. Heres a working copy of the final script. <script> var fieldName = "InsertRecordMultiListbox"; var x=document.getElementsByName(fieldName); x[0].multiple=true; function select_ (){ // get listbox element var listbox = document.getElementById("InsertRecordMultiListbox"); // get listbox length var len = listbox.options.length; // get selected element var selected = listbox.options[len-1].value; // verify if selected element contains comas, if yes, do the following if (selected.indexOf(",") != -1 ){ // Split selected option into array var m_array = new Array();m_array=selected.split (", "); // Delete last option from the listbox listbox.options.remove(len-1); // Go through listbox and select each option, if it is present in array for( var i=0; i< m_array.length; i++ ){for( var j=0; j< len-1; j++ ){ // Trim spaces while comparing elements from array and listbox if( m_array.replace(/^s+|s+$/g,"") == listbox.options[j].value ){ listbox.options[j].selected = "selected"; }}}}} window.onload = select_; </script> Quote Link to comment Share on other sites More sharing options...
Question
ppbb123
Hi,
I found the link how to select multiple values from a listbox in a WebForm, but how about the Update Form or Details page?
Thanks
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.