Form that results in a URL

Discussion in 'HTML' started by Christopher Grenness, Feb 5, 2004.

  1. I'm sure there's an easy solution here, but I couldn't narrow down an
    answer via Google (my search terms resulted in far to many hits).

    Here's what I want:

    A form with a one-line text box and a submit button.

    When I enter "test" in the text box and hit Submit, I'm taken to the
    URL http://xxxxxx.xxx/test

    When I enter "anothertest" in the text box and hit Submit, I'm taken
    to the URL http://xxxxxx.xxx/anothertest

    The domain name never has to change, just the last part of the URL
    should be changed based on what was entered via the form.

    Can anyone help?

    Best regards,

    Christopher


    --
    To reply via email, please use "grenness" instead of "kwjhdwedjw"
    and ".com" instead of ".invalid"
     
    Christopher Grenness, Feb 5, 2004
    #1
    1. Advertising

  2. Christopher Grenness

    Nik Coughin Guest

    Christopher Grenness wrote:
    > I'm sure there's an easy solution here, but I couldn't narrow down an
    > answer via Google (my search terms resulted in far to many hits).
    >
    > Here's what I want:
    >
    > A form with a one-line text box and a submit button.
    >
    > When I enter "test" in the text box and hit Submit, I'm taken to the
    > URL http://xxxxxx.xxx/test
    >
    > When I enter "anothertest" in the text box and hit Submit, I'm taken
    > to the URL http://xxxxxx.xxx/anothertest
    >
    > The domain name never has to change, just the last part of the URL
    > should be changed based on what was entered via the form.
    >
    > Can anyone help?
    >
    > Best regards,
    >
    > Christopher


    You could use Javascript (although some people turn it off).

    <input type="text" name="newLocation" size="20">
    <input type="button" value="Go" name="btnGo"
    onClick="location.replace('http://www.google.com/search?q='+document.getElem
    entById('newLocation').value)">

    You would replace the string http://www.google.com/search?q= with whatever
    your URL is.
     
    Nik Coughin, Feb 5, 2004
    #2
    1. Advertising

  3. Christopher Grenness

    Nik Coughin Guest

    Nik Coughin wrote:
    > Christopher Grenness wrote:
    >> I'm sure there's an easy solution here, but I couldn't narrow down an
    >> answer via Google (my search terms resulted in far to many hits).
    >>
    >> Here's what I want:
    >>
    >> A form with a one-line text box and a submit button.
    >>
    >> When I enter "test" in the text box and hit Submit, I'm taken to the
    >> URL http://xxxxxx.xxx/test
    >>
    >> When I enter "anothertest" in the text box and hit Submit, I'm taken
    >> to the URL http://xxxxxx.xxx/anothertest
    >>
    >> The domain name never has to change, just the last part of the URL
    >> should be changed based on what was entered via the form.
    >>
    >> Can anyone help?
    >>
    >> Best regards,
    >>
    >> Christopher

    >
    > You could use Javascript (although some people turn it off).
    >
    > <input type="text" name="newLocation" size="20">
    > <input type="button" value="Go" name="btnGo"
    >

    onClick="location.replace('http://www.google.com/search?q='+document.getElem
    > entById('newLocation').value)">
    >
    > You would replace the string http://www.google.com/search?q= with
    > whatever your URL is.


    You'd be much better off doing it server side however, say with PHP. Don't
    think the above JS would work in Mozilla, for starters, or many other non-IE
    browsers.
     
    Nik Coughin, Feb 5, 2004
    #3
  4. Christopher Grenness

    Bob Novell Guest

    Nik Coughin wrote:

    >Nik Coughin wrote:
    >
    >
    >>Christopher Grenness wrote:
    >>
    >>
    >>>I'm sure there's an easy solution here, but I couldn't narrow down an
    >>>answer via Google (my search terms resulted in far to many hits).
    >>>
    >>>Here's what I want:
    >>>
    >>>A form with a one-line text box and a submit button.
    >>>
    >>>When I enter "test" in the text box and hit Submit, I'm taken to the
    >>>URL http://xxxxxx.xxx/test
    >>>
    >>>When I enter "anothertest" in the text box and hit Submit, I'm taken
    >>>to the URL http://xxxxxx.xxx/anothertest
    >>>
    >>>The domain name never has to change, just the last part of the URL
    >>>should be changed based on what was entered via the form.
    >>>
    >>>Can anyone help?
    >>>
    >>>Best regards,
    >>>
    >>>Christopher
    >>>
    >>>

    >>You could use Javascript (although some people turn it off).
    >>
    >><input type="text" name="newLocation" size="20">
    >><input type="button" value="Go" name="btnGo"
    >>
    >>
    >>

    >onClick="location.replace('http://www.google.com/search?q='+document.getElem
    >
    >
    >>entById('newLocation').value)">
    >>
    >>You would replace the string http://www.google.com/search?q= with
    >>whatever your URL is.
    >>
    >>

    >
    >You'd be much better off doing it server side however, say with PHP. Don't
    >think the above JS would work in Mozilla, for starters, or many other non-IE
    >browsers.
    >
    >
    >

    That Javascript should work in Netscape. Why would it not work in
    Mozilla? Netscape 7.1 is based on Mozilla.

    I'l make up a page quickly and see if it does, indeed, work in Netscape
    7.1 -- be back in a few minutes.

    Bob
     
    Bob Novell, Feb 5, 2004
    #4
  5. Christopher Grenness

    Nik Coughin Guest

    >That Javascript should work in Netscape. Why would it not work in Mozilla?
    Netscape 7.1 is based on Mozilla.

    >I'l make up a page quickly and see if it does, indeed, work in Netscape

    7.1 -- be back in a few minutes.

    I said that it might not work, I didn't actually test it :) Maybe it works
    just as well with Mozilla and friends. It will definitely work with IE, I
    do stuff like that all the time on the intraweb at work.
     
    Nik Coughin, Feb 5, 2004
    #5
  6. Christopher Grenness

    Bob Novell Guest

    Re: Form that results in a URL - here's tested code

    Nik Coughin wrote:

    >>That Javascript should work in Netscape. Why would it not work in Mozilla?
    >>
    >>

    >Netscape 7.1 is based on Mozilla.
    >
    >
    >
    >>I'l make up a page quickly and see if it does, indeed, work in Netscape
    >>
    >>

    >7.1 -- be back in a few minutes.
    >
    >I said that it might not work, I didn't actually test it :) Maybe it works
    >just as well with Mozilla and friends. It will definitely work with IE, I
    >do stuff like that all the time on the intraweb at work.
    >
    >
    >


    It works on I.E. 6, Netscape 4.8, and Netscape 7.1 - after fixing some
    typos and changing the way you referenced the value of the input box,
    and setting location.href instead of using location.replace

    This is what I finally wound up with.

    <form>
    <input type="text" name="newLocation" size="20"><input type="button"
    value="GO" name="btnGo"
    onclick="window.location.href='http://www.google.com/search?q=' +
    newLocation.value">
    </form>

    Put this in a page and browse it and then you can put words in the input
    box and click the button and it take you to Google and search on the
    words form the input box.

    newLocation.value is an easier way to get the value of the input box.

    Setting window.location.href is a more appropriate way to go to another
    page rather than using the replace function.

    If you use the replace function, it will replace the entry in the
    history. If you simply set the value of location.href, it will be just
    as though you'd click a normally coded link - there will be an entry in
    the history for both the page with the form and the page to which it
    takes you.

    This code can easily be modified to create the href in some other format
    like Christopher needed.

    Bob

    Bob
     
    Bob Novell, Feb 5, 2004
    #6
  7. Christopher Grenness

    Nik Coughin Guest

    Re: Form that results in a URL - here's tested code

    Nice :)
     
    Nik Coughin, Feb 5, 2004
    #7
  8. Christopher Grenness

    Mark Parnell Guest

    On Thu, 5 Feb 2004 14:10:56 +1300, "Nik Coughin"
    <nrkn!no-spam!@woosh.co.nz> declared in alt.html:
    >
    > You'd be much better off doing it server side however, say with PHP. Don't
    > think the above JS would work in Mozilla, for starters, or many other non-IE
    > browsers.


    Better off doing it server side anyway, because it won't do anything for
    those with Javascript disabled/unavailable.

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
     
    Mark Parnell, Feb 5, 2004
    #8
  9. Christopher Grenness

    Mark Parnell Guest

    Re: Form that results in a URL - here's tested code

    On Thu, 05 Feb 2004 04:38:55 GMT, Bob Novell <> declared
    in alt.html:
    >
    > <form>


    Invalid - missing the required action="" attribute.

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
     
    Mark Parnell, Feb 5, 2004
    #9
  10. "Nik Coughin" <nrkn!no-spam!@woosh.co.nz> wrote in message news:<uKgUb.34412$>...
    > Nik Coughin wrote:
    > > Christopher Grenness wrote:
    > >> I'm sure there's an easy solution here, but I couldn't narrow down an
    > >> answer via Google (my search terms resulted in far to many hits).
    > >>
    > >> Here's what I want:
    > >>
    > >> A form with a one-line text box and a submit button.
    > >>
    > >> When I enter "test" in the text box and hit Submit, I'm taken to the
    > >> URL http://xxxxxx.xxx/test
    > >>
    > >> When I enter "anothertest" in the text box and hit Submit, I'm taken
    > >> to the URL http://xxxxxx.xxx/anothertest
    > >>
    > >> The domain name never has to change, just the last part of the URL
    > >> should be changed based on what was entered via the form.
    > >>
    > >> Can anyone help?
    > >>
    > >> Best regards,
    > >>
    > >> Christopher

    > >
    > > You could use Javascript (although some people turn it off).
    > >
    > > <input type="text" name="newLocation" size="20">
    > > <input type="button" value="Go" name="btnGo"
    > >

    > onClick="location.replace('http://www.google.com/search?q='+document.getElem
    > > entById('newLocation').value)">
    > >
    > > You would replace the string http://www.google.com/search?q= with
    > > whatever your URL is.

    >
    > You'd be much better off doing it server side however, say with PHP. Don't
    > think the above JS would work in Mozilla, for starters, or many other non-IE
    > browsers.


    It would, if it's coded properly. Your PHP suggestion is far better, though.

    --
    Hywel
     
    Hywel Jenkins, Feb 5, 2004
    #10
  11. >> You'd be much better off doing it server side however, say with PHP. Don't
    >> think the above JS would work in Mozilla, for starters, or many other non-IE
    >> browsers.


    >Better off doing it server side anyway, because it won't do anything for
    >those with Javascript disabled/unavailable.


    Thanks, guys.
    This is actually supposed to work mainly on PDAs, so I guess JS
    abilities are limited.
    How do I do it server side?
    Or is that way too complicated for a novice like myself?

    Thanks again!

    /Christopher

    --
    To reply via email, please use "grenness" instead of "kwjhdwedjw"
    and ".com" instead of ".invalid"
     
    Christopher Grenness, Feb 5, 2004
    #11
  12. Christopher Grenness

    Mark Parnell Guest

    On Thu, 05 Feb 2004 08:25:55 GMT, Christopher Grenness
    <> declared in alt.html:

    > How do I do it server side?
    > Or is that way too complicated for a novice like myself?
    >


    You would need the server to support a server-side scripting language,
    e.g. PHP, ASP, Perl, CGI, etc.

    PHP is supposed to be very easy for a "novice" to pick up. What you want
    wouldn't be particularly complicated. In fact, if you ask nicely,
    someone might even bash something quick out for you. ;-)

    --
    Mark Parnell
    http://www.clarkecomputers.com.au
     
    Mark Parnell, Feb 5, 2004
    #12
  13. Christopher Grenness

    Jeff Thies Guest

    "Mark Parnell" <> wrote in message
    news:t341h0jp83xa$...
    > On Thu, 05 Feb 2004 08:25:55 GMT, Christopher Grenness
    > <> declared in alt.html:
    >
    > > How do I do it server side?
    > > Or is that way too complicated for a novice like myself?
    > >


    Here's perl

    #!/usr/bin/perl

    use CGI;
    my $query=new CGI;
    my $page_path=$query->param('my_rolldown');

    print $query->redirect($page_path);



    the rolldown would look like this:

    <select name="my_rolldown">
    <option value="/some_path/some_page.html">page 1</option>

    ....

    That's a bit too simple, but will work. PHP and other languages will also be
    easy. That will work on almost any server and any web browser.

    Jeff




    >
    > You would need the server to support a server-side scripting language,
    > e.g. PHP, ASP, Perl, CGI, etc.
    >
    > PHP is supposed to be very easy for a "novice" to pick up. What you want
    > wouldn't be particularly complicated. In fact, if you ask nicely,
    > someone might even bash something quick out for you. ;-)
    >
    > --
    > Mark Parnell
    > http://www.clarkecomputers.com.au
     
    Jeff Thies, Feb 6, 2004
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon paugh
    Replies:
    1
    Views:
    943
  2. Monique Y. Mudama
    Replies:
    1
    Views:
    477
    Monique Y. Mudama
    Jun 28, 2005
  3. lovecreatesbeauty
    Replies:
    8
    Views:
    1,735
    Old Wolf
    Sep 12, 2005
  4. Ken Fine
    Replies:
    3
    Views:
    563
    Steven Cheng [MSFT]
    Jul 23, 2008
  5. Just D.
    Replies:
    0
    Views:
    549
    Just D.
    Aug 11, 2004
Loading...

Share This Page