Jump to content

changing image src based on hyperlink click


terrid25

Recommended Posts

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?

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

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.