It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Here's a 5 second question for all you experts

Here's a 5 second question for all you experts

Postby Iain on Fri Dec 01, 2006 9:49 am

It's my first day trying javascript... and I cannot understand why I cannot load an image subject to an "IF" condition....

What is wrong with this?

<script type="text/javascript">
if ...... //I'm ok with the condition//
{
img src="gifs/xxred.gif"
}
else
{
img src="gifs/xxgreen.gif"
}
</script>

All I wan't to do is make a gif appear based on a condition....

Can anyone help me with what I'm sure is the simplest of problems..!
Iain
 
Posts: 2
Joined: Thu Nov 30, 2006 11:19 am

Postby mwa103 on Fri Dec 01, 2006 5:05 pm

I'm no expert at Javascript, but I beleive if you want to show something conditionally you need to have:
document.write("<img src='gifs/xxred.gif'>");
instead of just img src="gifs/xxred.gif";

Hope this helps
-Mike
mwa103
100+ Club
 
Posts: 206
Joined: Mon Mar 07, 2005 10:55 pm

Postby ngpgeeta on Sun Dec 17, 2006 10:42 am

<html><head>
<script>
function change()
{
if(condition)
{
document.first.src="gifs/xxred.gif"
}
else
document.first.src="gifs/xxgreen.gif"

}
</script></head><body>
<img name="first" src="xx.gif"></body></html>

Now where you have to call function change(), you have to decide.Hope this helps!
ngpgeeta
 
Posts: 19
Joined: Sat Nov 18, 2006 11:30 am


Who is online

Users browsing this forum: No registered users and 5 guests