First please use the code icon (<>) to embed it in a post and choose the correct code format. It makes your code much easier to read. Second, there are several ways to accomplish what you want. Probably the most common way is to include the javascript in the PHP page you want executed. Run the javascript and return true or false then test that in the PHP code to determine if the data meets the requirements to run the script. If not then output an error or something, otherwise run the code. If you really want to execute a PHP script from javascript then you need to use Ajax. Just search for "PHP Ajax" and you will find plenty of references with examples.