Solved

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

Posted on 2014-09-16
7
373 Views
Last Modified: 2014-09-16
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
}
0
Comment
Question by:jabz ayuap
  • 3
7 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
Comment Utility
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
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Question is slightly confusing what should be happening when.

http://jsfiddle.net/46tm226x/

$(function () {
    $(".mytextbox").change(function () {
        if ($(this).val().trim() == "") {
            $(this).val("0")
        }
    })
})

Open in new window

0
 

Author Comment

by:jabz ayuap
Comment Utility
my other solution here is
$("#table").keyup(function(){
var press = $(this).val();
if($(this).val < 0)
{
       $(this).val(0.00)
}
0
 

Author Comment

by:jabz ayuap
Comment Utility
Thank you eenokami, I like to close this question but I don't know how to declare a close one, Sorry for the inconvenience
0
 

Author Comment

by:jabz ayuap
Comment Utility
Gary answer my question already and I really appreciate his help....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now