1,105,417 Community Members

Css and jquery

Member Avatar
techyworld
Posting Whiz in Training
242 posts since Sep 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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?

Member Avatar
JorgeM
IT Addict
6,409 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 960 [?]
Skill Endorsements: 172 [?]
Moderator
Featured
Sponsor
 
0
 

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
diafol
Where are my eyes?
12,970 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,847 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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>
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article