Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 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
    New Coder
    Join Date
    Feb 2006
    Posts
    18
    Thanks
    2
    Thanked 2 Times in 2 Posts
    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');

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    45
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    New Coder
    Join Date
    Feb 2006
    Posts
    18
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Smile 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 .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •