Question

I am currently working within the confines of sharepoint 2007 and have some code that turns a dropdownlist into a combobox. What i have works perfectly fine, however this code is meant to be used by business analysts and content creators so it has to be as simple as possible. So i am condensing it into a function and all has gone swimmingly except for the onChange event.

I have managed to extract the original onChange event, though due to my dropdownlist i have to replace a parameter. So i convert it to a string, replace the parameter and need to reconvert it to a function a la:

var onChangeFunction = "function (){alert("your function has been called")}"    

//The function 'attachEvent' is not common javascript. It is a custom function
//that works for my combobox.
combobox.attachEvent("onChange",(function)onChangeFunction);

Is that even possible?

Was it helpful?

Solution

You can use new Function but I think you are on a slippery slope playing with this.

var fn = new Function("{alert(\"your function has been called\")}")
combobox.attachEvent("onChange",fn);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top