Jump to content

I am having a hell of a time.


lamboman

Recommended Posts

Ok, I need two things, first. How would I specifie that these two links would be 2 different variables, the first one would be image1.gif, the second image2.gif

 

<p><a href='#' onClick='replaceImage();' title='Reload image'>option1</a></p>

<p><a href='#' onClick='replaceImage();' title='Reload image'>option2</a></p>

   

 

This is the second problem, How would I call up the image based on the button selected (right now this just calls up image1)

 

<img id="image" src='image1'/>

 

I hope this make some sort of sence.

Link to comment
https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/
Share on other sites

 
<script>
function replaceImage(id,img){

if(img == 1){
document.getElementById(id).innerHTML = "<img id='image' src='image1.gif'/>";
}else if(img == 2){
document.getElementById(id).innerHTML =  "<img id='image' src='image2.gif'/>";
}
}//end replaceImage
</script>
<p><a href='#' onClick="replaceImage('image',1); return false;" title='Reload image'>option1</a></p>
<p><a href='#' onClick="replaceImage('image',2); return false;" title='Reload image'>option2</a></p>

<img id="image" src='image1.gif'/>

No thats not quite working. Lets do it this way,. I need this to display the variable "image". Right now it just displays "image1". I need it do display the variable "image" which could be any number of pics depending what is selected.

 

 

<img id="image" src='image1'/>

my bad im doing 10 things at once.

 

 

<script>
function replaceImage(id,img){

if(img == 1){
document.getElementById(id).innerHTML = "<img src='http://www.wizecho.com/images/wiz_start.jpg'/>";
}else if(img == 2){
document.getElementById(id).innerHTML =  "<img src='http://i1.ytimg.com/vi/8jUU3yCy3uI/default.jpg'/>";
}
}//end replaceImage
</script>
<p><a href='#' onClick="replaceImage('image',1); return false;" title='Reload image'>option1</a></p>
<p><a href='#' onClick="replaceImage('image',2); return false;" title='Reload image'>option2</a></p>

<span id='image'><img src='http://i4.ytimg.com/vi/SvxkSKqY6cU/default.jpg'/></span>

 

Still not quite what I am looking for. Lets do it this way. 2 buttons, both with a different value.

 

<td><button type="button" replaceImage="image1">Show Image 1</button></td>

<td><button type="button" replaceImage="image2">Show Image 2</button></td>

 

All that I want to do is diplay the image depending what is selected.

 

<img id="image" src='replaceImage'/>  (i belive this is all I need help with, I just need to display the variable)

Youll have to replace the whole element

 

<script>
function img(id,img){
document.getElementById(id).innerHTML = "<img src='"+img+"'/>";
}//end replaceImage
</script>
<td><button type="button" onclick="img('x','image1.gif');">Show Image 1</button></td>
<td><button type="button" onclick="img('x','image2.gif');">Show Image 2</button></td>

<span id='x'>Default img<br /><img src='http://i4.ytimg.com/vi/SvxkSKqY6cU/default.jpg'/></span>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.