Solved

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

Posted on 2014-09-16
7
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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…
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.

634 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