0

How can I call java script in php or can convert same php code in js. Please explain I am new to javascript

<?php
  if(isset($_POST['Submit']))
{
     $user_name = $_POST['login_name'];                                            
     if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0)
     {
       $msg="<span style='color:red'>The Validation code does not match!</span>";
}else{
       echo "<script>FormSubmit();</script>";  //how to call here
 }   
}
?>

<html>
<body>
    <form name="ddd" id="ddd">
      <label>name:</name></label>
             <input id="login_name" type="text" />
      <button  type="submit" onclick="return validate(); value="Submit">
    </form> 

  <script>
    function FormSubmit(){
     ................
     ................

   }
   </script>
</body>
</html>

Thanks in advance.

1
  • put your php block below your html Commented May 20, 2015 at 10:52

2 Answers 2

1

Try this.

<html>
<body>
    <form name="ddd" id="ddd">
      <label>name:</name></label>
             <input id="login_name" type="text" />
      <button  type="submit" onclick="return validate(); value="Submit">
    </form> 
<?php
  if(isset($_POST['Submit']))
{
     $user_name = $_POST['login_name'];                                            
     if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0)
     {
       $msg="<span style='color:red'>The Validation code does not match!</span>";
}else{
       echo "<script>FormSubmit();</script>";  //how to call here
 }   
}
?>
  <script>
    function FormSubmit(){
     // JS logic goes here

   }
   </script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

1 Comment

You'll also need to move the FormSubmit function definition script block either before the PHP, or into the head.
0

The problem is FormSubmit function is definied after calling it on PHP

The solution is defining FormSubmit function before calling

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.