Jump to content

Check The Value Of A Text Box


aspquestions
 Share

Recommended Posts

I want to do something like if the value of a text box is empty then assign a value of 0 to it.But if(document.getElementById("mytextbox").value ==null) does not work. (I have an alert in the if and it does not reach it). if(document.getElementById("mytextbox").value ==null){ document.getElementById("mytextbox").value = "1"; alert("entered if");}How do I do this..Also if I want to use the text box to keep count.. that is, if textbox.value = 1 then textbox.value = textbox.value + 1.. How do I do this?

Link to comment
Share on other sites

if(document.getElementById("mytextbox").value ==null)Dont' test for null, test for the empty string:if(document.getElementById("mytextbox").value == "")You can use parseInt to get a number from a field and increment it:

var num = parseInt(document.getElementById("mytextbox").value, 10);if (isNaN(num))  num = 0;num++;document.getElementById("mytextbox").value = num;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...