Member_2_5230414
asked on
javascript count up but cant count down
$(document).ready(function () {
$("#textbox").keyup(function () {
var box = $(this).val();
var main = box.length * 100;
var value = (main / 140);
var count = 140 - box.length;
if (box.length <= 140) {
$('#count').html(count);
}
else {
HERE!!!
}
});
});
I can count down to 0 but how can i continue to count down into the minus and
-1
-2
-3
-4 ect
what is the above code is trying to do?
You don't need if else part
$(document).ready(function () {
$("#textbox").keyup(function () {
var box = $(this).val();
var main = box.length * 100;
var value = (main / 140);
var count = 140 - box.length;
$('#count').html(count);
});
});
ASKER
sonawanekiran:
with that code would there be any way of disabling my button <asp:Button Text="Submit" CssClass="submit" type="submit" id="Submit" value="Submit" runat="server" />
if the count goes under 0??
thats why i was going to use the else
with that code would there be any way of disabling my button <asp:Button Text="Submit" CssClass="submit" type="submit" id="Submit" value="Submit" runat="server" />
if the count goes under 0??
thats why i was going to use the else
ASKER
also i need to turn the txt red below 0 to alert the user!
Hmmm...ok
$(document).ready(function () {
$("#textbox").keyup(functi on () {
var box = $(this).val();
var count = 140 - box.length;
if (box.length <= 140) {
$('#count').html(count);
}
else {
$(this).attr("readonly","r eadonly");
}
});
});
$(document).ready(function
$("#textbox").keyup(functi
var box = $(this).val();
var count = 140 - box.length;
if (box.length <= 140) {
$('#count').html(count);
}
else {
$(this).attr("readonly","r
}
});
});
$(document).ready(function () {
$("#textbox").keyup(functi on () {
var box = $(this).val();
var count = 140 - box.length;
if (count > 0) {
$('#count').html(count);
}
else {
$(this).attr("readonly","r eadonly");
$('#count').html("count reached 0 now");
$('#count').css("color", "red");
}
});
});
$("#textbox").keyup(functi
var box = $(this).val();
var count = 140 - box.length;
if (count > 0) {
$('#count').html(count);
}
else {
$(this).attr("readonly","r
$('#count').html("count reached 0 now");
$('#count').css("color", "red");
}
});
});
Just add below code in else part
$('#count').html(count);
$(". submit").attr("disabled",t rue);
$('#count').html(count);
$(". submit").attr("disabled",t
ASKER
$('#count').html("count reached 0 now"); - how do i chnage this to minuses?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.