Reputation: 23
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
Reputation: 3497
var person = {
lastname: null,
firstname: null
};
alert(person.lastname === null);
Upvotes: 0
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
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