SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to open php page when button is clicked in javascript? (newbie question)

    PHP page workout_now.php
    HTML Code:
    ...
    <div id="playworkout"><button onClick="playWorkout()">Play Workout</button></div>
    ...
    JAVASCRIPT
    Code:
    function playWorkout(){
       ...
       ...
       ...
         }
    function playWorkout() will build an array of values that will be passed as a parameter, but for now I simply want to know the best way to
    open "play_workout.php" and close "workout_now.php" when function playWorkout() is called?

    Thanks so much!

  2. #2
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So this seems to do the trick. Not sure which one is better to use:

    window.location = 'http://localhost/RealCardio/play_workout.php';
    document.location = 'http://localhost/RealCardio/play_workout.php';

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by n2cardio View Post
    So this seems to do the trick. Not sure which one is better to use:

    window.location = 'http://localhost/RealCardio/play_workout.php';
    document.location = 'http://localhost/RealCardio/play_workout.php';
    window.location is the more correct usage - document.location even though it is supported, is not part of any standard.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •