Solved

chnage char count to number count

Posted on 2011-09-29
13
219 Views
Last Modified: 2012-05-12
 // This will count char within the textbox
   $(document).ready(function () {
                                            $("#textbox").keyup(function () {
                                                var box = $(this).val();
                                                var count = 140 - box.length;
                                                if (count > 0) {
                                                    $('#count').html(count);
                                                       $(".submit").attr("disabled",false);
                                                       $('#count').css("color", "black");
                                                }
                                                else {
                                                                $('#count').html(+ count );
                                                    $('#count').css("color", "red");
                                                    $(".submit").attr("disabled",true);
                                                }
                                            });
                                        });  

Open in new window


the above code counts how many char are in my textbox

using vb.net to get a number from a data base
 Dim tildays As Decimal = dateallreadybooked.counttilleft("Jarratt")
' Dim tildays As Decimal = 7

Open in new window


match the value in the textbox to the tildays value and if over        $(".submit").attr("disabled",true);

e.g

if the user types in 7 then it will show $(".submit").attr("disabled",false);
but if they do 7.1 it iwll be $(".submit").attr("disabled",true);
0
Comment
Question by:runnerjp2005
  • 6
  • 5
  • 2
13 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36814002
how is number count different from char count?
0
 

Author Comment

by:runnerjp2005
ID: 36814048
well if i type in 7 wont the output be 1?  and if i type in 71 it will be 2??

i need it to be if it is 7  it means 7
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36814179
so you also want to make sure that only numbers are typed in?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 82

Expert Comment

by:leakim971
ID: 36814282
Use parseInt : http://repository.unikom.ac.id/man/www.w3schools.com/jsref/jsref_parseint.asp.htm

parseInt("7.1") return 7
parseInt("71") return 71
parseInt("7ffsffsf") return 7

you may use parseInt("7.1").toString().length
0
 

Author Comment

by:runnerjp2005
ID: 36814496
i need to use this though

 // This will count char within the textbox
   $(document).ready(function () {
                                            $("#textbox").keyup(function () {
                                                var box = $(this).val();
                                                var count = 140 - box.length;
                                                if (count > 0) {
                                                    $('#count').html(count);
                                                       $(".submit").attr("disabled",false);
                                                       $('#count').css("color", "black");
                                                }
                                                else {
                                                                $('#count').html(+ count );
                                                    $('#count').css("color", "red");
                                                    $(".submit").attr("disabled",true);
                                                }
                                            });
                                        });  

Open in new window


and instead of counting the character using  var count = 140 - box.length;

i check to be if the number in the box is less then Dim tildays As Decimal = 7


so ...

if box.char < 7
(".submit").attr("disabled",false);
                                                       $('#count').css("color", "black");

else
        $('#count').css("color", "red");
                                                    $(".submit").attr("disabled",true);

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36814642
where's << Dim tildays As Decimal = 7 >>

a variable server side?
if yes, put its value in an hidden field to check it later with js :

<input type="hidden" id="tildays" value="7" /> (or asp:Hidden)

var box = parseInt( $(this).val() );
if( box < $("#tildays").val() ) {
      $(".submit").attr("disabled",false);
      $('#count').css("color", "black");
}
else {
        $('#count').css("color", "red");
        $(".submit").attr("disabled",true);
}

0
 

Author Comment

by:runnerjp2005
ID: 36815491
    <script>
   // This will count char within the textbox
   $(document).ready(function () {
       $("#username").keyup(function () {
        var box = parseInt($(this).val());
        if (box < $("#tildays").val()) {
            $(".booktil").attr("disabled", false);
                }
        else {
            
            $(".booktil").attr("disabled", true);
        }
    });
});  
</script>

<asp:Panel ID="tiltab" runat="server" Visible="false">
        <center>
        <div id="tiltab2">
            <br />
            Date Selected: <asp:Label ID="thedate" runat="server" Text="Label"></asp:Label> <br /><br />
         
            <asp:Label ID="ampmlabel" runat="server" Visible="false"></asp:Label> <asp:DropDownList Visible="false" ID="ampmfull" runat="server">
                <asp:ListItem>Am</asp:ListItem>
                <asp:ListItem>Pm</asp:ListItem>
            </asp:DropDownList> <br />  
             No Of Hours: 
                       <input type='text' id='username'><asp:Label ID="tildays" runat="server" Visible="False"></asp:Label> &nbsp;
            <div ID="username_availability_result">
            </div>
            <br />
            <br />
            Comments:<br />
            <asp:TextBox ID="TextBox1" runat="server" Height="78px" TextMode="MultiLine" 
                Width="319px"></asp:TextBox>
            <br />
            <br />
            Please note that this will need to be approved before shown on the calender.<br />
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
            <br />
            <asp:Button ID="booktil" runat="server" Text="Book Til" />
            <asp:Button ID="canceltil" runat="server" Text="Cancel" />
                 </div>  </center>
    </asp:Panel>

Open in new window



code behind being

     Dim tildays1 As Decimal = dateallreadybooked.counttilleft("Jarratt")
' dateallreadybooked.counttilleft("Jarratt") get the value 7

        tildays.Text = tildays1

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36815604
so?
0
 

Author Comment

by:runnerjp2005
ID: 36816087
sorry it does not work...
0
 

Author Comment

by:runnerjp2005
ID: 36816090
when i say does not work...no action isperformed
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36816206
what do you get in the alert with the following :


<script>
   // This will count char within the textbox
   $(document).ready(function () {
       $("#username").keyup(function () {
        var box = parseInt($(this).val());
alert("box:"+box+"\ntildays:"+$("#tildays").val()+"\nbox < $("#tildays").val() : "+(box < $("#tildays").val()));
        if (box < $("#tildays").val()) {
            $(".booktil").attr("disabled", false);
                }
        else {
            
            $(".booktil").attr("disabled", true);
        }
    });
});  
</script>

<asp:Panel ID="tiltab" runat="server" Visible="false">
        <center>
        <div id="tiltab2">
            <br />
            Date Selected: <asp:Label ID="thedate" runat="server" Text="Label"></asp:Label> <br /><br />
         
            <asp:Label ID="ampmlabel" runat="server" Visible="false"></asp:Label> <asp:DropDownList Visible="false" ID="ampmfull" runat="server">
                <asp:ListItem>Am</asp:ListItem>
                <asp:ListItem>Pm</asp:ListItem>
            </asp:DropDownList> <br />  
             No Of Hours: 
                       <input type='text' id='username'><asp:Label ID="tildays" runat="server" Visible="False"></asp:Label> &nbsp;
            <div ID="username_availability_result">
            </div>
            <br />
            <br />
            Comments:<br />
            <asp:TextBox ID="TextBox1" runat="server" Height="78px" TextMode="MultiLine" 
                Width="319px"></asp:TextBox>
            <br />
            <br />
            Please note that this will need to be approved before shown on the calender.<br />
            <br />
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
                    <asp:Button ID="Button1" runat="server" Text="Button" />
                </ContentTemplate>
            </asp:UpdatePanel>
            <br />
            <br />
            <asp:Button ID="booktil" runat="server" Text="Book Til" />
            <asp:Button ID="canceltil" runat="server" Text="Cancel" />
                 </div>  </center>
    </asp:Panel>

Open in new window

0
 

Author Comment

by:runnerjp2005
ID: 36816328
alert("box:"+box+"\ntildays:"+$("#tildays").val()+"\nbox < $("#tildays").val() : "+(box < $("#tildays").val()));

seems to be an error here
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36816558
thanks, corrected : alert( "box:" + box + "\ntildays:" + $("#tildays").val() + "\nbox < $(\"#tildays\").val() : " + (box < $("#tildays").val()) );
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question