Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a web form that I am masking textboxes and unmasking them. When the user enters a value into the masked textbox and clicks or tabs to the next masked textbox the unmasked value is shown next to the masked textbox using a Label. I am trying to get it to display in a textbox. Why is this not working? It works for the label but not for the textbox.

HTML
<script src="Jquery Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="Jquery Scripts/jquery.maskedinput.js" type="text/javascript"></script>
    <script type='text/javascript'>
        $(document).ready(function () {

            $.mask.definitions['~'] = "[+-]";
            $("#TextBox1").mask('?999,999');
            $("#TextBoxY").mask('?999,999');

            $("#TextBox1").blur(function () {
                $("#lblinfo").html(" " + $(this).mask());
                $("#TextBoxY").blur(function () {
                    $("#TextBoxinfo2").html(" " + $(this).mask());
                }).dblclick(function () {
                    $(this).unmask();


                });
            });
        });


    </script>
Posted
Comments
Kornfeld Eliyahu Peter 30-Sep-14 15:38pm    
The sequence of your code is somehow unclear to me...
Why you bind TextBoxY.blur only inside TextBox1.blur?
Computer Wiz99 30-Sep-14 15:50pm    
I mask the value in TextBox1 and then I unmask it to lblinfo when the user clicks or tabs to the next field. Just to show how the unmasking works. I just wanted to know why can't it display the unmask in a textbox?
Sergey Alexandrovich Kryukov 30-Sep-14 16:20pm    
What are you doing?! In one blur handler, you setup another blur handler. Do you understand that this setup will be repeated over and over?
Don't do it; it may cost you a big trouble.
—SA

1 solution

I still can't understand why you are do that binding inside the event handler - it seems to me as a dangerous (and useless) thing, that can create you endless handlers (according to the times first text-box get blur!)...
To your point...jQuery html method used to set inner html for elements, to set its value you should use val method...
JavaScript
$("#TextBoxinfo2").val(" " + $(this).mask());

(It works on label because of the differnt nature of <label> and <input>...)
 
Share this answer
 

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