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>
<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) {    
        curnum = 1;}


        curnum = 2;}

Anyone can help?

4 Years
Discussion Span
Last Post by diafol

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.


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:


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>
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.