if(document.form1.captcha.value != '$_SESSION["code"]'){
        alert("Wrongwrong captcha \n");
        return false;
    }

hello ,i just want to ask why is it not running ?i decided to convert my php function to javascript . thank you

You are not understanding the fundamental difference between javascript and php. PHP is run before the page loads, and has all of its output before the page loads. Javascript runs at run-time - that is, as the browser "reads" the script, it attempts to execute it (unless means are taken to prevent this, such as making functions or other closures, which can then be called through DOM events).

What you have above is a mix of script that will run whenever, mingled with a PHP value that doesnt exist once the page is rendered.

Without knowing context, there is not way to help you. Is this generated from the PHP? Is this written on the page and expected to execute? Is this a dynaimcally created script that loads via a src?

There are too many variables to really understand what you are trying to do.

But i suggest not to use javascript to veriy captcha, always check in handler php code.