Functions in JavaScript

5 pts.
Tags:
JavaScript
JavaScript functions
Web development
function pcs() { var t1=document.getElementById("tot1").value var pb=document.getElementById("pcbox").value var pc="" if(t1==! && pb==!) { document.getElementId("rbox").innerHTML="" } } My question is if the value t1 & pb = null means the function pcs() is not writern...How?

Answer Wiki

Thanks. We'll let you know when a new response is added.

You need to test t1 and pb for null before accessing the value property, e.g.

var t1 = document.getElementById(“tot1”);
var x;
if (t1 != null) {
x = t1.value;
}

The value property always returns a string, so it will never be null, because string objects return empty string but not null.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: