javascript variable in html tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim J

    #1

    javascript variable in html tag

    Hi all

    I've got a html doc with <embed src="url.svg"> in it

    however, I'd like the source to be a javscript variable (which will
    depending on an if, be a different filename on loading)

    is this possible and if so, what is the syntax to put a javascript variable
    inside an embed tag?

    thanks


  • Randy Webb

    #2
    Re: javascript variable in html tag

    Tim J wrote:
    [color=blue]
    > Hi all
    >
    > I've got a html doc with <embed src="url.svg"> in it
    >
    > however, I'd like the source to be a javscript variable (which will
    > depending on an if, be a different filename on loading)
    >
    > is this possible and if so, what is the syntax to put a javascript variable
    > inside an embed tag?
    >
    > thanks
    >
    >[/color]

    window.onload= setEmbedSrc;

    function setEmbedSrc(){
    if (condition){
    newFileName = 'someFile1.svg' ;
    }else{
    newFileName = 'someFile2.svg' ;
    }
    document.getEle mentById('myDep recatedEmbedTag ').src=newFileN ame;
    }

    <embed id="myDeprecate dEmbedTag" src="whoCaresIA mGoingToChangeI tAnyway.svg">

    Untested. Its Midnight, I am too lazy to test.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    Working...