Web Analytics Made Easy -
StatCounter Reuse Function For Multiple Selects - CodingForum

Announcement

Collapse
No announcement yet.

Reuse Function For Multiple Selects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reuse Function For Multiple Selects

    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:

    Code:
    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

  • #2
    Just give the function a few arguments like this

    Code:
    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

    Code:
    insertHTML('IDofTheElement');

    Comment


    • #3
      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

      Comment


      • #4
        pixel2life

        No need to go out and buy books, there are tons of free resources online. I usually find tutorials on http://www.pixel2life.com .

        Comment

        Working...
        X