Jump to content

Dynamically populating dropdown list with strings starting with a *


Greywacke

Recommended Posts

hi there, i have a little function that receives an array, with the elements that are to be headings, starting with a *.here is what the two dimentional array looks like (as retrieved from xml).

"* Option Title",	{		"option text 1",		"option value 1"	},	{		"option text 2",		"option value 2"	},	{		"option text 3",		"option value 3"	}

and here is the function:

function addflags(arr) {	var sel = document.getElementById("menu_flags");	for (var i = 0; i < arr.length; i++) {		var opt = document.createElement('option');		alert(arr[i]);		if (arr[i][0]) {			opt.text = strRepeat("\u00a0",5) + arr[i][0];			opt.value = arr[i][1];			try {				sel.add(opt, null);	// standards compliant; doesn't work in IE			}			catch(ex) {				sel.add(opt);		// IE only			}		} else {			opt.text = arr[i];			opt.value = 0;			try {				sel.add(opt, null);	// standards compliant; doesn't work in IE			}			catch(ex) {				sel.add(opt);		// IE only			}		}	}}

now there is one dropdown, where if you select a flag - it inserts it into a textarea. there are different types of flags, all seperated by the values with 0. if one of these is selected, it does nothing. but why are the rest of the strings as shown by the alert, not in the options? i think the * is causing some sort of regular expression to be performed... truncating i guess i can always insert the unicode value for it - or somehow make sure that regular expressions are not performed on the string arr.oh yeah, the function is called for every flags tag that is found in the xml, here is the current xml piece where the data is retrieved from:

<flags name="* Insert Service Attribute">	<flag name="Budget" value="%ATTRIBUTE Budget%" />	<flag name="Fitment" value="%ATTRIBUTE Fitment%" />	<flag name="Requirement" value="%ATTRIBUTE Requirement%" />	<flag name="budget" value="%ATTRIBUTE budget%" />	<flag name="canopy_req" value="%ATTRIBUTE canopy_req%" />	<flag name="canopy_style" value="%ATTRIBUTE canopy_style%" />	<flag name="fitment" value="%ATTRIBUTE fitment%" />	<flag name="products_description" value="%ATTRIBUTE products_description%" />	<flag name="vehicle_make_model" value="%ATTRIBUTE vehicle_make_model%" /></flags><flags name="* Insert Configurable Text"></flags><flags name="* Insert Consumer Variables">	<flag name="Consumer Name" value="%CONSUMERNAME%" />	<flag name="Consumer E-mail" value="%CONSUMEREMAIL%" />	<flag name="Consumer City/Town" value="%CONSUMERCITY%" /></flags><flags name="* Insert Environmental Variables">	<flag name="Service Description" value="%SERVICENAME%" />	<flag name="Region Description" value="%REGIONNAME%" />	<flag name="Supplier Name" value="%SUPPLIERNAME%" /></flags>

how can i insert a string retrieved from xml that is starting with a * as an option text? searching the web has failed to get me an answer closer to what i know sofar. any help with this would be greatly appreciated :)

Link to comment
Share on other sites

ahh... nevermind, it seemed thek checking of wether the element was an array or a string was not working. what worked better was to check if an asterisk (*) existed in the element for the titles, and if the second element of the subarray existed for the flags. :)this issue is now RESOLVED ^^

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...