Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-6
rated 0 times [  1] [ 7]  / answers: 1 / hits: 14391  / 11 Years ago, tue, january 14, 2014, 12:00:00

I'm trying to hide and show the password of the user but I'm having a hard time. Here is my markup:



<td>Username: <td>
<td><input type=text class=form-control value=<?php echo $row['Username'];?>readonly><td>
<td><input type=button class=btn btn-primary show value=Show Password>
<input type=button class=btn btn-primary hide value=Hide Password style=display:none;><td>
</tr>
<tr class=password style=display:none;>
<td>Password: <td>
<td><input type=text class=form-control value=<?php echo $row['Password']; ?> readonly><td>
</tr>


And my jQuery



$(.show).click(function(){
$('.hide').show();
$('.show').hide();});

More From » jquery

 Answers
9

Your HTML is invalid, you need to wrap a table tag around a tr tag or the tr and everything in it will return undefined in Javascript:



<table>
<tr>
<td>Username:
<td>
<td>
<input type=text class=form-control value=<?php echo $row['Username'];?> readonly>
<td>
<td>
<input type=button class=btn btn-primary show value=Show Password>
<input type=button class=btn btn-primary hide value=Hide Password style=display:none;>
<td>
</tr>
<tr class=password style=display:none;>
<td>Password:
<td>
<td>
<input type=text class=form-control value=<?php echo $row['Password'];?> readonly>
<td>
</tr>
</table>


and to complete your JQuery, you could use this:



$(.show).click(function () {
$('.hide').show();
$(this).hide();
$('.password').eq(0).show();
});

$('.hide').click(function () {
$('.show').show();
$(this).hide();
$('.password').eq(0).hide();
});


DEMO


[#48735] Monday, January 13, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominics

Total Points: 424
Total Questions: 99
Total Answers: 107

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
dominics questions
Wed, Apr 6, 22, 00:00, 2 Years ago
Thu, Jan 13, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
;