0

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?

3
  • Please Read: stackoverflow.com/questions/469150/… Commented Jan 23, 2009 at 11:53
  • Be nice with him. Think it's a valid question. Commented Jan 23, 2009 at 21:46
  • This is not even valid syntax. Commented Dec 1, 2024 at 14:12

3 Answers 3

6

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();

Sign up to request clarification or add additional context in comments.

Comments

3

The line if(t1==! && pb==!) is nonsense - did you mean if (!t1 && !pb)?

Comments

2

if(t1==! && pb==!) --> this is absolutly wrong.... What are you trying to check?

Maybe if(t1!="" && pb!="")?

Comments

Your Answer

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