originsone
asked on
Change HTML document based on Variable
Alright, this one has got to be easy. I'm just too new to javascript to figure out what I'm doing wrong.
I'm trying to have the HTML document run this line "<image src="mypic.jpg" height="255" width="352" name=myimage>" by changing a variable to X. Otherwise, if the variable is anything else I don't want any line to be written to the HTML document at all. I'm using this for a webcam and usually I have to search through the HTML document for this line and then comment it out when i don't want a pic to show.
This was my attempt:
<head>
<script language="JavaScript">
var activate = x;
fuction camActivation(){
activation = document.write('<image src="ChillCam2.jpg" + height="255" + width="352" + name=ChillCam2>');
if(activate=x)}
else {
document.write('')
}
</script>
</head>
-------------------------- ---------- ---
<body>
<SCRIPT LANGUAGE="JavaScript">
camActivation();
</script>
</body>
Again, I'm fairly new to javascript so I may be totally off base with my approach.
I'm trying to have the HTML document run this line "<image src="mypic.jpg" height="255" width="352" name=myimage>" by changing a variable to X. Otherwise, if the variable is anything else I don't want any line to be written to the HTML document at all. I'm using this for a webcam and usually I have to search through the HTML document for this line and then comment it out when i don't want a pic to show.
This was my attempt:
<head>
<script language="JavaScript">
var activate = x;
fuction camActivation(){
activation = document.write('<image src="ChillCam2.jpg" + height="255" + width="352" + name=ChillCam2>');
if(activate=x)}
else {
document.write('')
}
</script>
</head>
--------------------------
<body>
<SCRIPT LANGUAGE="JavaScript">
camActivation();
</script>
</body>
Again, I'm fairly new to javascript so I may be totally off base with my approach.
fuction camActivation(){
if(activate==x){
document.writeln('<img src="ChillCam2.jpg" + height="255" + width="352" + name="ChillCam2" />');
}
}
if(activate==x){
document.writeln('<img src="ChillCam2.jpg" + height="255" + width="352" + name="ChillCam2" />');
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all,
Thank you all so much for your assistance with this. All seemed great answers...but jonnal's was the only I could seem to get to work correctly. However, If I changed the variabled to anything outside a number...it would not work properly. So, i couldn't use "No" or "Yes" as a variable instead of 15 (or any other number.
Eitherway, it worked!
Thank you all so much for your assistance with this. All seemed great answers...but jonnal's was the only I could seem to get to work correctly. However, If I changed the variabled to anything outside a number...it would not work properly. So, i couldn't use "No" or "Yes" as a variable instead of 15 (or any other number.
Eitherway, it worked!
script language="javascript">
var g_strActivate = "yes";
function CamActivation( )
{
// Do we should the pic?
if( g_strActivate == "yes" )
{
// Yes
document.getElemntById( "webcam" ).style.visibility="visibl
}
}
</script>
<html>
<body onload="CamActivation( );">
<div id="webcam" style="visibility: hidden;">
<image src="mypic.jpg" height="255" width="352" name=myimage>
</div>
</body>
</html>