SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using javascript variable in PHP without submitting a form?

    Hey,

    I am trying to create an online music player that allows saving and loading playlists.

    I've already implemented the saving part, now I'm trying to implement the Load part.
    The "playlist" file is just a text file with the song names in it. I need to populate the select box with those songs by reading each line. This is not difficult for me- just open the file, read the lines and echo in the javascript code to add an option with that value. The problem is, I need to know the name of the playlist that is selected to be loaded. (If this is unclear, go to the address provided above to see exactly).
    The only way I know of recieving the playlist name is by submitting it through a form and using _REQUEST[]. However, this is not an option because it redirects the user to the script- therefore not being able to populate the select box.

    I am pretty new to PHP, so I'm not exactly sure how it all works. Mayber there is a way to submit within the page? If not, any other suggestions and help would be great. Thanks.
    Last edited by HAWK; Jul 22, 2012 at 22:40.

  2. #2
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Posts
    1,295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a way to do it, and I believe it goes by the name of AJAX. I've never used it but from what you say sounds like it should do the trick. Look around the forums/Google and you'll find plenty of info.

    Alex
    "The proper function of man is to live - not to exist."
    Get a Free TomTom


  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any help on exactly how I would use this in my specific scenario?

    I've never used XMLHttpRequest before... I've been reading on it but can't figure out exactly how this would work for me.

    I need to send the selectedIndex value to the php file using XMLHttpRequest, correct?
    Then in the php file I need to open that file and read it.
    This is all fine, but then how would I add an option to the select box using this information?
    Only way I can think of is echoing the javascript to do so- Which can't be done from a separate file.

    Help please.

  4. #4
    SitePoint Wizard bronze trophy bigalreturns's Avatar
    Join Date
    Mar 2006
    Posts
    1,295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry like i said i havent used it so I dont have a clue. Try posting in the ajax forum and you'll probably get a better response.
    "The proper function of man is to live - not to exist."
    Get a Free TomTom



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
  •