Reputation:
Example:
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 t1
and pb
are null the function pcs()
is not called... Why?
Upvotes: 0
Views: 142
Reputation: 103837
The line
if(t1==! && pb==!)
is not legal syntax. If this is exactly how you have written the code it will not parse and thus the function will not be defined (plus you'll be getting Javascript errors).
Perhaps you meant
if(t1 != null && pb != null)
Additionally, while semicolons at the end of lines can be inferred by the interpreter, they are meant to be there (as opposed to being actually optional) and adding them is good practice.
EDIT and while I didn't understand your final question 100%, remember that the code you've written (assuming the syntax were correct) merely defines a function. You will need to have some other code call this function at an appropriate point in order to have it executed, e.g. for some element onblur = pcs();
Upvotes: 6
Reputation: 321806
The line if(t1==! && pb==!)
is nonsense - did you mean if (!t1 && !pb)
?
Upvotes: 3
Reputation: 8269
if(t1==! && pb==!)
--> this is absolutly wrong.... What are you trying to check?
Maybe if(t1!="" && pb!="")
?
Upvotes: 2