Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello. I have a web form that I made in VS 2010 ASP.NET. I have a jQuery plugin for the web form. I have the masking done. When a user enters a number value in the textbox and clicks or tabs to the next textbox the value entered is displayed as an unmasked value. When the user enters a new value in the second textbox the current unmasked value disappears. I would like to display both values for each textbox. How can I do this? Also, I masked the textbox value to be 999,999,999,999. If a user only has 123,456. How can I get the textbox to keep that value instead of loosing it?

Here is my code:

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>jQuery Masked Input Demo</title>
    <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'>
        $(function () {
            $.mask.definitions['~'] = "[+-]";
            $("#TextBoxY").mask("999,999,999,999");
            $("#TextBox1").mask("999,999,999,999");

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



        });
    });

    </script>

    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 245px;
        }
        .style3
        {
            width: 66px;
        }
        .style4
        {
            width: 245px;
            text-align: left;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    <table class="style1">
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBoxINST_ID" runat="server"></asp:TextBox>
            </td>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" 
                    Width="100px" /> 
            </td>
        </tr>
        <tr>
            <td class="style3">
                Hourly</td>
            <td class="style4">
                <asp:TextBox ID="TextBox1"  runat="server" Width="180px" 
                    AutoCompleteType="Email" ClientIDMode="Static" 
            style="text-align: left"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                Yearly</td>
            <td class="style4">
    <asp:TextBox ID="TextBoxY" runat="server" Width="180px" 
                    AutoCompleteType="Email" ClientIDMode="Static" 
            style="text-align: left"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            </td>
            <td>
                <asp:Label ID="lblinfo" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBox3" runat="server" ontextchanged="TextBox3_TextChanged" 
                    AutoPostBack="True"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td class="style3">
                 </td>
            <td class="style2">
                <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
            </td>
            <td>
                 </td>
        </tr>
    </table>
    </form>
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 29-Sep-14 15:41pm    
What is that unmasked value? The value you get using the property value is exactly what you need.
What are you "loosing", exactly?
The clause "If a user only has 123,456." is in complete. Than what?

You can give an example with 3 values commented as: 1) mask, 2) entered value, 3) "lost" value. If you do, I guess it will be easy to answer.

—SA
Computer Wiz99 29-Sep-14 15:55pm    
This is what I am trying to find out. The jQuery I have masks textbox1 and textboxY. The code looks like this for both masked textboxes:

$("#TextBox1").mask("999,999,999,999");
$("#TextBoxY").mask("999,999,999,999");

A user can enter 123,456,789,101 and the format will unmask and display to the right of the textbox. What if the user only enters 123,456. The masked numbers disappears when going to another textbox. How can I get the code to the point to where it will mask any number without entering all of the numbers required?

1 solution

I fixed the unmasked of each value that is entered into the textbox and displayed on the left of the textbox. Here is my code:

ASP.NET
<head runat="server">
    <title>jQuery Masked Input Demo</title>
    <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,999,999");
            $("#TextBoxY").mask("999,999,999,999");

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


        });
    });
});
 
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