Solved

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

Posted on 2014-09-16
7
380 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

786 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