?
Solved

chnage char count to number count

Posted on 2011-09-29
13
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
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:Gurvinder Pal Singh
ID: 36814179
so you also want to make sure that only numbers are typed in?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 2000 total points
ID: 36816558
thanks, corrected : alert( "box:" + box + "\ntildays:" + $("#tildays").val() + "\nbox < $(\"#tildays\").val() : " + (box < $("#tildays").val()) );
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

777 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