Hi i have a registration form .. somewhere in my form i have an image(registration is written) btw div tag:

<div id="test"> <img src="..."/></div>
<label>username:</label>
.......
....
...
<div><label onclick=Onchange(1)>Login</label></div>

Now i have an option :login" on this form if user has already registered. When click on "login" the image login should be visible (on top) and the image registration should disapear.

The code below is with text and it works. but when i change it to image, it does not work. That is login and registration is written in the form of an image.

function Onchange(num){
        if (num == 1) {    
        $('#test').html("Login");
        curnum = 1;}

        else{

        $('#test').html("Registration");
        curnum = 2;}
    }

Anyone can help?

The html() method will just set the HTML contents of each element. So based on the partial code you provided, this "<img src="..."/>" will be replaced by the text in your Onchange() function.

If you are trying to show/hide an image, in this scenrio, you would have to take the image out of the contents of the Div and use other methods such as show(), hide().

without knowing the full picture, its hard for me to provide a best overall approach.

Member Avatar for diafol

To test whether an user has already logged in, you'd be safer using server-side code to hold a session variable. All js code can be circumvented, so using it to handle this sort of thing may not be appropriate. Ajax is being used more and more to deal with login.

As Jorge states, you need to pass data that will change the image. Using the src attribute of an image is probably the easiest:

$('#someimageid').attr('src','path/file.png');

Is this form meant to accept registration data and login data depending on the content of the div? E.g.

<div><label onclick=Onchange(1)><img id="someimageid" src="img/login.png" /></label></div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.