...

View Full Version : Reuse Function For Multiple Selects



7079
10-11-2006, 07:50 PM
Hi,

I have this function that I am using in one of my apps. I need helping in making the function usable for multiple drop downs on the same page. I could copy and paste the function and modify the names so that I have a unique function for each select menu, but I know there is a better way.

Here is the function:



function insertHTML() {
var thisSelect = document.getElementById("delims");
thisval = thisSelect.options[thisSelect.selectedIndex].value;
if(thisval.length > 1){
tinyMCE.execInstanceCommand("mce_editor_0","mceInsertContent",false,thisval);
}
}


Any suggestions or help will be greatly appreciated!

Thanks,

7079

codyodell
10-11-2006, 08:25 PM
Just give the function a few arguments like this



function insertHTML(ID){
var thisSelect = document.getElementById(ID);
thisval = thisSelect.options[thisSelect.selectedIndex].value;
if(thisval.length > 1){
tinyMCE.execInstanceCommand("mce_editor_0 ","mceInsertContent",false,thisval);
}
}


now when you call your function just specify the arguments like this



insertHTML('IDofTheElement');

7079
10-11-2006, 08:39 PM
codyodell,

Thanks for the quick reply, i knew it was going to be something that simple.

Any recommendations on any books or sites for learning Javascript more in depth? I really would like to further my knowledge so that I can become a JS programmer.

Thanks again!

7079

codyodell
10-11-2006, 08:42 PM
No need to go out and buy books, there are tons of free resources online. I usually find tutorials on http://www.pixel2life.com .



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum