We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,642 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Css and jquery

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?

3
Contributors
2
Replies
9 Hours
Discussion Span
3 Months Ago
Last Updated
3
Views
techyworld
Junior Poster
198 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

JorgeM
Senior Poster
3,997 posts since Dec 2011
Reputation Points: 294
Solved Threads: 543
Skill Endorsements: 115

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>
diafol
Keep Smiling
Moderator
10,625 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0593 seconds using 2.68MB