terrid25 Posted December 9, 2010 Share Posted December 9, 2010 Hi I have a captcha image, that is generated by a PHP script. Currently the user can change the captcha, by clicking on the image, but I'd like this to be done by clicking on a hyperlink 'Change captcha' My current code is: <a href='' onClick='return false' title='Reload image'> <img src='/index.php/captcha?<?php echo time(); ?>' onClick='this.src="/index.php/captcha?r=" + Math.random() + "&reload=1"'> </a> Can someone advise me on how to achieve this? Link to comment https://forums.phpfreaks.com/topic/221111-changing-image-src-based-on-hyperlink-click/ Share on other sites More sharing options...
brianlange Posted December 9, 2010 Share Posted December 9, 2010 Create a function that is triggered by the link'ss onclick event. <script> function switchImage() { var image = document.getElementById('myImage'); image.src = 'http://www.realtown.com/img/main/rt-logo.png'; } </script> Here's my working example: http://www.realtown.com/test23.php Link to comment https://forums.phpfreaks.com/topic/221111-changing-image-src-based-on-hyperlink-click/#findComment-1145035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.