javascript - Changing If - Else function to return multiple values? -
so javascript code below using pull info our automated marketing software eloqua. works single-select drop downs. want work multi-select drop downs.
i know productvalue variable works. said positive in if(productvalue == productlist[i].value) " .value " since calling value on in drop-downs. there way create multiple? has been driving me nuts days.
function customerinformation() { var productvalue = "<span class=eloquaemail>marketingcustomerinformation1</span>"; //field merge...field merge working var productlist = document.getelementbyid('c_marketing_customer_information1').options; //calling contact record field for(var i=0; i< productlist.length; i++) { if(productvalue == productlist[i].value) { document.getelementbyid('c_marketing_customer_information1').value = productvalue; break; } else { document.getelementbyid('c_marketing_customer_information1').value = "select"; } } }
you utilize multiple loops:
var productvalue = "<span class=eloquaemail>marketingcustomerinformation1</span>"; //field merge...field merge working var productlist = document.getelementbyid('c_marketing_customer_information1').options; //calling contact record field for(var i=0; i< productlist.length; i++) { for(var j=0;j<productvalue.length;j++) { if(productvalue[j] == productlist[i].value) { document.getelementbyid('c_marketing_customer_information1').option[i].selected="selected"; } } }
could add together boolean var select default when nil gets selected.
basic idea
the first loop go through values in multi-select list. the sec loop go through values pass (meaning productvalue need array of values want selected). if current item in first array (productlist[i]) equal (==) current item in sec array (productvalue[j]) mark alternative selected.some useful tools js needs:
google w3schools.com firebug (firefox addon, though browsers have tied f12 can help, utilize see variables , step through functions) javascript function if-statement
No comments:
Post a Comment