0

How to set default value null in javascript as we make a db field null.

lastName.value="Null";

But it saves as values given

6
  • 2
    Um... lastName.value = null; Commented May 29, 2013 at 12:18
  • Is lastName an input field? Then use lastName.value = "". Commented May 29, 2013 at 12:19
  • you don't have to assign null value specifically... if you declare a variable without providing value by default it will hold null in it... Commented May 29, 2013 at 12:20
  • 1
    @PavanKumarK Undefined variables are undefined, not null. Commented May 29, 2013 at 12:20
  • Now what type of thing is this? Commented May 29, 2013 at 12:41

6 Answers 6

2

Like this:

lastName.value=null;
Sign up to request clarification or add additional context in comments.

Comments

2

"Null" is a string

lastName.value= null use this to set null value

Comments

0

I suggest you totally avoid declaring it and it will take the value of undefined - which you can check against where required.

For example:

if(lastName.value == undefined) {
   // do stuff ...
}

Comments

0
<html>
<head>
<script type="text/javascript">
function Hello()
{
    var a=document.getElementById('nm').value;
    alert(a);
    document.getElementById('nm').value=null;
    alert(document.getElementById('nm').value);
}
</script>
<body>
Name : <input type="text" name="nm" id="nm" />
<input type="button" value="CLick" onclick="Hello()"/>
</body>
</head>
</html>

Comments

0
var person = {
    lastname: null,
    firstname: null
};


alert(person.lastname === null);

1 Comment

be sure to check for null with the === operator as == will cast undefined to null.
-2

try

lastName.value= undefined;

It will pass null value to server

1 Comment

undefined is not null, and the question never mentions passing values to the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.