T
tosbalok
I have a variable (really a constant) defined in a .js file. The
contents of the variable is the source location for an image (there
are actually several. The idea is, you click an image and the
javascript will swap the image source out - an on image, an off image,
you get the idea).
Now here's the problem: I also have to a copy of the button that is
visible when the page loads. That's easy enough to do *if* I simple
type out the src= attribute of the image. I don't want to do that. I
have this constant defined in the .js file. I want to make use of it.
<html>
<head>
<script language="javascript">
// this constant is defined in a .js file
ImgSrc = "/webpresence/resources/common/icon/twistie/plus/
icn_twistyall_closed.gif";
</script>
</head>
<body>
<!-- I need to create an image that uses the src defined above. Old
way is: -->
<img src="/webpresence/resources/common/icon/twistie/plus/
icn_twistyall_closed.gif"/>
<!-- I'm looking for a better option than hardcoding the src. -->
<!-- I want to make use of the variable, ImgSrc. Here's the only idea
I came up with -->
<script language="javascript">document.write("<img src='" + ImgSrc +
"' />");</script>
</body>
</html>
contents of the variable is the source location for an image (there
are actually several. The idea is, you click an image and the
javascript will swap the image source out - an on image, an off image,
you get the idea).
Now here's the problem: I also have to a copy of the button that is
visible when the page loads. That's easy enough to do *if* I simple
type out the src= attribute of the image. I don't want to do that. I
have this constant defined in the .js file. I want to make use of it.
<html>
<head>
<script language="javascript">
// this constant is defined in a .js file
ImgSrc = "/webpresence/resources/common/icon/twistie/plus/
icn_twistyall_closed.gif";
</script>
</head>
<body>
<!-- I need to create an image that uses the src defined above. Old
way is: -->
<img src="/webpresence/resources/common/icon/twistie/plus/
icn_twistyall_closed.gif"/>
<!-- I'm looking for a better option than hardcoding the src. -->
<!-- I want to make use of the variable, ImgSrc. Here's the only idea
I came up with -->
<script language="javascript">document.write("<img src='" + ImgSrc +
"' />");</script>
</body>
</html>