Results 1 to 9 of 9

Thread: Multiple Redirections on a Submit Button (with Text Field)?

  1. #1
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Multiple Redirections on a Submit Button (with Text Field)?

    Basically, what I'm trying to do seems very simple, but I can't seem to figure out how to do it.

    I have a text field and corresponding submit button at the top of my webpage. I have five keywords that users could possibly enter into the text field, and depending on which one the user enters, the submit button should direct them to one of the five corresponding pages. It's like a search function but much, much smaller and simpler, I think.

    Is there a way to do this? Any help is appreciated! Thank you!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Having:

    five keywords that users could possibly enter into the text field
    is rather a bad idea to begin with. There are virtually an infinite number of words and word-like strings that could be entered. This concept seems more aptly suited to a select element, or perhaps to 5 radio buttons.

    To really be of much help though, we would need to see the code involved, preferably via a link to the page on your site that you are having the problem with.

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Having:



    is rather a bad idea to begin with. There are virtually an infinite number of words and word-like strings that could be entered. This concept seems more aptly suited to a select element, or perhaps to 5 radio buttons.

    To really be of much help though, we would need to see the code involved, preferably via a link to the page on your site that you are having the problem with.

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    The site isn't nearly done yet...I haven't even implemented the code into the page, I was just compiling different features that I'd insert into the code afterward. I understand it isn't the best idea, but there really are a limited amount of keywords they could enter. Is this task even possible (bad of an idea as it may be), or no?

    Edit: Also, to compensate for any strange/erroneous keywords, could I add a function where any non-specified keyword (other than the main five) would just redirect to a sixth page?
    Last edited by Unwind23; 02-05-2008 at 05:08 PM. Reason: Added idea/thought.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function kWord(f){
    switch(f.elements['kword'].value.toLowerCase()){
    case 'google':
    window.location.href='http://www.google.com';
    break;
    case 'yahoo':
    window.location.href='http://www.yahoo.com';
    break;
    case 'msn':
    window.location.href='http://www.msn.com';
    break;
    case 'dd':
    window.location.href='http://www.dynamicdrive.com';
    break;
    case 'ask':
    window.location.href='http://www.ask.com';
    break;
    default: window.location.href='http://www.loisimages.com';
    }
    }
    </script>
    </head>
    <body>
    <form action="javascript:void();" onsubmit="kWord(this);return false;">
    <input type="submit" value="Go!">
    <input type="text" name="kword">
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    If this must be done, going along with John, I would opt for the radio button/check box option, give them the 5 to choose from, thus eroding any errors from possible input.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  6. #6
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    You guys are awesome.

    THANK YOU!!

  7. #7
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'd hate to bug you guys again since you've been so incredibly helpful to me so far, but I hit a small snag...

    One of the keywords I'd like them to enter features a quotation mark in it ( " ). However, the function doesn't seem to recognize the quotations and just sends those search queries to the default results page. Is there a way to have the quotation marks recognized?

    (The search term is 32" Waist)

    Thank you so much again for your help!
    Last edited by Unwind23; 02-08-2008 at 09:14 PM. Reason: Added specific search term.

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Simply add something like the following for whichever keyword you want (the highlighted part is the one with the quotation mark in it).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function kWord(f){
    switch(f.elements['kword'].value.toLowerCase()){
    case 'google':
    window.location.href='http://www.google.com';
    break;
    case 'yahoo':
    window.location.href='http://www.yahoo.com';
    break;
    case '"testing"':
    window.location.href='http://www.thetestingsite.net';
    break;
    case 'msn':
    window.location.href='http://www.msn.com';
    break;
    case 'dd':
    window.location.href='http://www.dynamicdrive.com';
    break;
    case 'ask':
    window.location.href='http://www.ask.com';
    break;
    default: window.location.href='http://www.loisimages.com';
    }
    }
    </script>
    </head>
    <body>
    <form action="javascript:void();" onsubmit="kWord(this);return false;">
    <input type="submit" value="Go!">
    <input type="text" name="kword">
    </form>
    </body>
    </html>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I feel stupid -- I noticed that I was using an inch symbol in the code rather than quotations. I swapped the characters and now it works perfectly. Sorry about that, thanks for the 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
  •