SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member fitzy75's Avatar
    Join Date
    Mar 2006
    Location
    Horsham, West Sussex, United Kingdom
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Trying to submit using hyperlink

    I had a quick search of the forums but didn't know quite what to search for. And I know this PHP section of the forums probably isn't the right place to post this but I couldn't find a HTML section.

    Anyway, on with my problem.

    Basically I am developing a web interface for a media player called Winamp.

    I want to have a set of radio buttons which will decide what radio stream to add to the playlist, and when I click one of the radio buttons it puts the url of the stream into a text box on the page.

    Then I am using a submit buttin to make winamp play the stream, but the url which is submitted has to contain the url of the stream like this:
    http://server:port/index.html?clear&add=http://streamurl:port&play

    Basically the "clear" part of it clears the current playlist, "add=" adds the stream url to the playlist and "play" starts it playing.

    I have got this setup working well using a submit button with the following code:

    Code:
    <input name="continue" type="button" id="continue" value="Click Here to Play Stream" onclick="window.location='index.html?clear&add='+url.value+'&play'">
    But my problem is that I need to use a hyperlink to do this (for complicated reasons) instead of a submit button. I have experimented with this a bit and come up with the following code:

    Code:
    <a href="http://10.0.1.2:8002/index.html?clear&add='+url.value+'&play">Play the selected Stream</a>
    However this code doesn't work as it doesn't substitute "+url.value+" for the value in the text box.


    Does anyone know how I can achieve this?

  2. #2
    SitePoint Zealot joazito's Avatar
    Join Date
    Mar 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this works:

    <a href="javascript:window.location='index.html?clear&add='+url.value+'&play'">Play the selected Stream</a>

    If it doesn't, you can use onclick on an hyperlink too.

  3. #3
    SitePoint Member fitzy75's Avatar
    Join Date
    Mar 2006
    Location
    Horsham, West Sussex, United Kingdom
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the quick reply.

    Unfortunatly neither of those methods worked.

    I'll explain a bit about the situation. Basically I have a web server on my home network which is accessible from the outside world, but the pages which control winamp are on a different server which is only accessible from inside the network. So I am basically using a script called PHProxy to tunnel through the main server to the internal one (it is password protected with htaccess and restricted to that particular destination so security should be ok).
    The problem I think is that PHProxy doesn't properly support javascript so when I try the suggestions you said about it gives a 404 error:
    The requested URL /javascript:window.location='index.html was not found on this server.
    So I think the link would have to begin with index.html and then somehow incorporate the value in the text box if possible.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fitzy75 View Post
    Code:
    <a href="http://10.0.1.2:8002/index.html?clear&add='+url.value+'&play">Play the selected Stream</a>
    However this code doesn't work as it doesn't substitute "+url.value+" for the value in the text box.


    Does anyone know how I can achieve this?
    FYI the reason that link doesn't work is that the browser doesn't know that you're trying to use JavaScript to fill in values, since the browser doesn't automatically switch into JavaScript mode just because you're using JavaScript syntax in the middle of a hyperlink.

    joazito is thinking along the right lines, but the solution still won't work. You need to use:

    Code:
    <a href="javascript:window.location.href='http://10.0.1.2:8002/index.html?clear&add=' + document.FORM_NAME_HERE.url.value + '&play'">Play the selected Stream</a>

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to declare those variables in your java. I think you are missing the .href at the end of your window.location. It should be window.location.href = 'yourlink.html'

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're making it way too difficult:

    Code:
    <a href="javascript:form.submit();">Play the selected Stream</a>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry, that was wrong.

    Code:
    <a href="javascript:formName.submit();">Play the selected Stream</a>
    Saying that "formName" is the name of the form you want to submit. To also add the other GET values, just put hidden input fields and values.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    SitePoint Member fitzy75's Avatar
    Join Date
    Mar 2006
    Location
    Horsham, West Sussex, United Kingdom
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to do it without javascript? Basically it's not trying to submit a form, but in effect just click a hyperlink, but the hyperlink has to include the contents of the text box.

    The trouble is that to access this page from the outside world I have to browse it through a web proxy script called PHProxy, the reason for this is that it is on my home adsl connection which only has 1 IP, so 2 webservers both running on port 80 (and I don't want to run it on a different port) so I just tunnel one server through the other using the proxy script to connect to the internal IP.
    The problem here is that the proxy script doesn't properly support javascript so I am looking for a way to do it without.

    Is this possible? Or should I just make a list of hyperlinks, as in one for each stream url.

    So to clarify, can I use the contents of the text box as part of the hyperlink without the use of javascript?

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    SitePoint Member fitzy75's Avatar
    Join Date
    Mar 2006
    Location
    Horsham, West Sussex, United Kingdom
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok then I'll give up on that one and just have a long list of urls.

    Thanks for your help.


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
  •