desithugg Posted April 6, 2007 Share Posted April 6, 2007 <head> <script language='javascript'> fliplink = 'http://pca.x3teamz.net/pic2.php?poke=zapdos'; function flip(card) { var imgnum = ('but'+card); document.imgnum.src = fliplink; } </script> </head> <body> <table border='1'> <tr> <td><img name='but0' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(0);'></td> <td><img name='but1' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(1);'></td> <td><img name='but2' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(2);'></td> <td><img name='but3' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(3);'></td> <td><img name='but4' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(4);'></td> </tr> </table> </body> Umm lets say you click one of the images and the function flip(3); is called for <script language='javascript'> fliplink = 'http://pca.x3teamz.net/pic2.php?poke=zapdos'; function flip(card) { var imgnum = ('but'+card); document.imgnum.src = fliplink; } </script> Now here the card variable holds the value 3 and than I use that to make the variable imgnum which now holds the value 'but3' I want to update the image link with the name 'but3' or in othercases whatever value the variable imgnum has Umm might be a bit confusing im not sure how to word it really. Link to comment https://forums.phpfreaks.com/topic/45828-variables/ Share on other sites More sharing options...
mainewoods Posted April 10, 2007 Share Posted April 10, 2007 add an id= to your image tags: <td><img name='but3' id='but3' src='http://pca.x3teamz.net/pic2.php?poke=oddish' onclick='flip(3);'></td> change your function: function flip(card) { var imgnum = ('but'+card); document.getElementById(imgnum).src = fliplink; } Link to comment https://forums.phpfreaks.com/topic/45828-variables/#findComment-225534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.