Solved

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

Posted on 2014-09-16
7
391 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
ID: 40325412
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
ID: 40325883
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
ID: 40326748
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
ID: 40327066
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
ID: 40327301
Gary answer my question already and I really appreciate his help....
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Collecting Customer Data 5 38
utf-8 issues 11 136
ASP.NET Identity - Support Individual accounts and on-premises AD 1 77
502 - Web server received an invalid response 4 93
A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

821 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