Sundas Subhani
Sundas Subhani

Reputation: 23

Javascript default value null

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

lastName.value="Null";

But it saves as values given

Upvotes: 0

Views: 2646

Answers (6)

mccainz
mccainz

Reputation: 3497

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


alert(person.lastname === null);

Upvotes: 0

Panchotiya Vipul
Panchotiya Vipul

Reputation: 1296

<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>

Upvotes: 0

vijay
vijay

Reputation: 1353

try

lastName.value= undefined;

It will pass null value to server

Upvotes: -2

techfoobar
techfoobar

Reputation: 66663

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 ...
}

Upvotes: 0

PSR
PSR

Reputation: 40318

"Null" is a string

lastName.value= null use this to set null value

Upvotes: 2

Gung Foo
Gung Foo

Reputation: 13558

Like this:

lastName.value=null;

Upvotes: 2

Related Questions