Link to home
Start Free TrialLog in
Avatar of jabz ayuap
jabz ayuap

asked on

how can I set textbox set to 0 if textbox is empty

my textbox is dynamic, upon creating I set the view value to zero and the user can be able to create then upon updating the textbox, I want to set the value into zero if the textbox was empty by user how can I solve this problem using jquery or condition?
For example
if(textbox == empty)
{
     @model = 0
}
else
{
     @model
}
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

You want to trim the white space in case your users only enter a space, but you can check the length and the n set the value. Something along these lines should work.

var inp = $("#txt").val();
if(jQuery.trim(inp).length <= 0)
{
   $("#txt").val() = 0
}


stackoverflow.com/questions/1565193/check-if-textbox-has-empty-value
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jabz ayuap
jabz ayuap

ASKER

my other solution here is
$("#table").keyup(function(){
var press = $(this).val();
if($(this).val < 0)
{
       $(this).val(0.00)
}
Thank you eenokami, I like to close this question but I don't know how to declare a close one, Sorry for the inconvenience
Gary answer my question already and I really appreciate his help....