lamboman Posted May 31, 2011 Share Posted May 31, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/ Share on other sites More sharing options...
dreamwest Posted May 31, 2011 Share Posted May 31, 2011 <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'/> Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222701 Share on other sites More sharing options...
lamboman Posted May 31, 2011 Author Share Posted May 31, 2011 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'/> Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222705 Share on other sites More sharing options...
dreamwest Posted May 31, 2011 Share Posted May 31, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222706 Share on other sites More sharing options...
lamboman Posted May 31, 2011 Author Share Posted May 31, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222708 Share on other sites More sharing options...
dreamwest Posted May 31, 2011 Share Posted May 31, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222709 Share on other sites More sharing options...
lamboman Posted May 31, 2011 Author Share Posted May 31, 2011 Just what I needed, I cant thank you enogh. Quote Link to comment https://forums.phpfreaks.com/topic/237945-i-am-having-a-hell-of-a-time/#findComment-1222720 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.