Hi, I want that onsubmit, the system will fire the javascript first to validate the form and after getting OK result then it will call PHP function to connect/receive data from database
@NogDogJun 02.2014 — #[code=html] <form action="your_php_script.php" method="post" onsubmit="return yourJavascriptFunction();"> [/code] Then define the JavaScript function to return true if validated successfully, otherwise return false.
Unless you want some sort of AJAX implementation, in which case your JavaScript function would use an AJAX request to a PHP file that would execute the desired function and return whatever it is the JS function needs as the response.
@hafizfarooqauthorJun 02.2014 — #ok, i have got this clue from the net, but it is also not working... pls check [CODE] echo "<script type = "javascript"> var x = document.forms['frmlogin']['txtuser'].value; if (x ==null || x=="") { alert ("Missing username !"); return false; exit; </script>";
@deathshadowJun 03.2014 — #And don't forget that malicious users can easily bypass your JavaScript, so you still have to do any necessary validation on the server side, too.[/QUOTE] Which is why one should also make the page work securely without JavaScript first, since any data from user-side is suspect and should be re-validated on the server too.