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.

originsoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

justinbilligCommented:
do something like this

script language="javascript">


var g_strActivate = "yes";



function CamActivation( )
{
      // Do we should the pic?
      if( g_strActivate == "yes" )
      {
            // Yes
            document.getElemntById( "webcam" ).style.visibility="visible";
      }
}

</script>

<html>
      <body onload="CamActivation( );">
            <div id="webcam" style="visibility: hidden;">
                  <image src="mypic.jpg" height="255" width="352" name=myimage>
            </div>
      </body>
</html>
0
knightEknightCommented:
fuction camActivation(){

if(activate==x){
  document.writeln('<img src="ChillCam2.jpg" + height="255" + width="352" + name="ChillCam2" />');
}
}
0
jonnalCommented:
hi originsone
you need to put the script tags that print the line in the <body> part of the page
the if will detect the variable and execute or not : note the  == in the test condition

the script in the body will fire as the page loads
<head>

<script language="JavaScript">
var activate = 15;
</script>

</head>

<body>

<script language="JavaScript">

if(activate==15)  
{
document.writeln('<image src="ChillCam2.jpg" height="255" width="352" name=ChillCam2>');
}

</script>

</body>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
originsoneAuthor Commented:
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!

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.