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

help with script

help with script

Postby lamboman on Tue May 31, 2011 3:47 am

Here is what I need. I have loaded the variables and the function.
Next I have some buttons that have different variables(images)
now I just need to display the image acording to what button is pressed. this is what i have so far but now I am stuck.

<script language="JavaScript">

function showimage(){
var mainimage=new Array()
mainimage[1]="image1.gif"
mainimage[2]="image2.gif"
mainimage[3]="image3.gif"
}
</script>

<body>

<button type="button" mainimage[1]="image1()">Show Image 1</button>
<button type="button" mainimage[2]="image1()">Show Image 2</button>
<button type="button" mainimage[3]="image1()">Show Image 3</button>


<script language="JavaScript">
{
document.write "showimage" (This is where I need help) :roll:
}
</script>
lamboman
 
Posts: 2
Joined: Mon May 30, 2011 9:29 pm

Re: help with script

Postby rajmv on Thu Jul 14, 2011 6:22 pm

<head>
<script language="JavaScript">
<!--
function showimage(imgSrc){
document.getElementById('image').src = '/path/to/' +imgSrc;
//the '/path/to'+ you only need if the images are not in the same directory as where this html comes from
}
-->
</script>
</head>
<body>
<div><img id="image"/></div>
<button type="button" onclick="showImage('image1.gif')">Show Image 1</button>
<button type="button" onclick="showImage('image2.gif')">Show Image 2</button>
<button type="button" onclick="showImage('image3.gif')">Show Image 3</button>
</body>
rajmv
100+ Club
 
Posts: 103
Joined: Thu Jul 14, 2011 7:22 am


Who is online

Users browsing this forum: No registered users and 4 guests