[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Change HTML document based on Variable

Posted on 2004-11-29
4
Medium Priority
?
704 Views
Last Modified: 2008-01-09
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.

0
Comment
Question by:originsone
4 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 12698404
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 12698424
fuction camActivation(){

if(activate==x){
  document.writeln('<img src="ChillCam2.jpg" + height="255" + width="352" + name="ChillCam2" />');
}
}
0
 
LVL 4

Accepted Solution

by:
jonnal earned 150 total points
ID: 12702394
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
 

Author Comment

by:originsone
ID: 12707400
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question