Results 1 to 3 of 3

Thread: embed HTML using javascript

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    embed HTML using javascript

    Hi,

    I'm trying to load a js file and a textbox into an HTML file. I'm using the following code.

    Code:
     document.getElementById("yyyy").innerHTML = '<script type="text/javascript" src="http://yyyyy.js"></script> <input type="text" name="yyyyBox" onKeyUp="convert()">';
    The textbox is loaded successfully, however the js file is not loaded, i'm not able to call a function that is inside the js file.

    Error msg
    Code:
    test.html:1 Uncaught ReferenceError: convert is not defined

    I was wondering if there is a way to get this working.


    Thanks

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: embed HTML using javascript

    I use JS/jQuery to load both HTML and "new JS functions" - AJAX call to get the TEXT (sometimes in a file on the server and sometimes from a table in a database).

    If the "text" is a function I use EVAL() to load it into the DOM.

    Code:
            function compileFormula(intGO) {
                eval("g_objGrid[intGO].formula = function(currentRow,currentCell,item) {" 
                            + g_objGrid[intGO].formulaSource + "\n}");
            }
    If the "text" is HTML I use jQuery to load it into the DOM.

    Code:
    strEP = g_editpanels[strFromTo] || "";
    if (strEP.length == 0) {
        strEP = "<br /><span>Edit Panel not found, please try to log in again.</span>";
    }
    $(strEP).css("display", "none").appendTo(strEditPanel).addClass("acs-edit-bottom")
                        .removeAttr("id").attr("id", strNewId);
    wesEP = $("#" + strNewId);

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: embed HTML using javascript

    Take a look at this article on loading scripts

    http://www.html5rocks.com/en/tutoria...cript-loading/
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

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



Click Here to Expand Forum to Full Width