Does Javascript work inside a PHP file?

Discussion in 'Programming' started by chriswick, Mar 1, 2008.

  1. #1
    Hello Everyone!

    I'm making an PHP form and want to rediect the sumbit.php back to the form page, I want to do this with Javascript all I want to know is does Javascript function inside a PHP file?
     
    chriswick, Mar 1, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Well you can output the javascript code like this:

    
    echo "<script>location.href='form.php'</script>";
    exit(); // So the other html code won't appear.
    
    PHP:
    Or why not just redirect using PHP?

    
    header("Location: form.php");
    
    PHP:
     
    rkquest, Mar 1, 2008 IP
    chriswick likes this.
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Yes you can.

    You can insert Javascript within PHP or vise-versa.

    Peace,
     
    Barti1987, Mar 1, 2008 IP
    chriswick likes this.
  4. chriswick

    chriswick Peon

    Messages:
    907
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for you help guys + rep for both of you :)
     
    chriswick, Mar 1, 2008 IP