Solved

# chnage char count to number count

Posted on 2011-09-29
217 Views
`````` // This will count char within the textbox
\$("#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);
}
});
});
``````

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
``````

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
Question by:runnerjp2005
• 6
• 5
• 2

LVL 40

Expert Comment

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

Author Comment

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

ID: 36814179
so you also want to make sure that only numbers are typed in?
0

LVL 82

Expert Comment

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

ID: 36814496
i need to use this though

`````` // This will count char within the textbox
\$("#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);
}
});
});
``````

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

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

ID: 36815491
``````    <script>
// This will count char within the textbox
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>
<br />
<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>
``````

code behind being

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

tildays.Text = tildays1
``````
0

LVL 82

Expert Comment

ID: 36815604
so?
0

Author Comment

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

Author Comment

ID: 36816090
when i say does not work...no action isperformed
0

LVL 82

Expert Comment

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

``````<script>
// This will count char within the textbox
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>
<br />
<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>
``````
0

Author Comment

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

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

## Featured Post

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…