Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
am using this javascript to onclick method in my checkbox click.. but it is not working thats y i put this method in my html source page..


XML
<script type="text/javascript">
       $(function () {
           $("#show_password").bind("click", function () {
               var txtPassword = $("#password");
               var txtnewpassword = $("#");
               if ($(this).is(":checked")) {
                   txtPassword.after('<input onchange = "PasswordChanged(this);" id = "txt_' + txtPassword.attr("id") + '" type = "text" value = "' + txtPassword.val() + '" readonly = "readonly" />');
                   txtPassword.hide();


               } else {
                   txtPassword.val(txtPassword.next().val());
                   txtPassword.next().remove();
                   txtPassword.show();
               }
           });
       });

</script>



HTML
<div class="edit-rght-2">
    <input type="password" disabled="disabled" value="sevika" 
        id="password" maxlength="10" readonly="readonly" /><input type="checkbox" id="show_password"  önclick="show_password();"/><label>Show</label>
</div>
Posted
Comments
Ramug10 7-Mar-14 2:20am    
did you checked with OnClientClick="show_password()"..
[no name] 7-Mar-14 3:04am    
onclient click is not working in this program..am using html input..not asp.net

Please try is as below.

HTML


HTML
<div class="edit-rght-2">
    <input type="password" disabled="disabled" value="sevika" id="password" maxlength="10" readonly="readonly" />
    <input type="checkbox" id="show_password" />
        <label>Show</label>
    </input>
</div>

JS


C#
$('#show_password').change(function(){  
    if ($(this).is(':checked')) {
        alert('checked');
        //your code
    }
    else{
        alert('unchecked');
       //your code
    }
});

LIVE DEMO


JsFiddle
 
Share this answer
 
v4
Comments
thatraja 7-Mar-14 2:35am    
Beat me to it, 5!
Sampath Lokuge 7-Mar-14 2:36am    
Thanks Thatraja. :)
[no name] 7-Mar-14 3:25am    
when i click the show button check box the real data display on the text box
Sampath Lokuge 7-Mar-14 3:32am    
Sorry, I couldn't get what you told.So can you give more info ?
[no name] 7-Mar-14 3:38am    
k.u can show a check box in my program.when i checked the text box the input data will showing in input box..so i wanted to create a onclick method for the above jquery program..can u help me..i was already tried but it not working in onclick method.
You are trying to toggle the show and hide of the password, right? The javascript code looks alright. Did you happen to forget to include a jquery library in the html page?
 
Share this answer
 
v2
Comments
[no name] 7-Mar-14 3:27am    
i have jquery lbry .when i put this code to in my apsx source page the method will work it..but i was created a onclick method in my jquery file..but its not working
Peter Leow 7-Mar-14 3:44am    
comment out this, and it should work now.
//var txtnewpassword = $("#");
and you can remove this too, it is redundant:
önclick="show_password();
[no name] 7-Mar-14 3:46am    
its not a part of my program thats y i ommented man...
Peter Leow 7-Mar-14 3:48am    
it is working now?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900