Results 1 to 8 of 8

Thread: onclick Redirect from form entry - need help

  1. #1
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default onclick Redirect from form entry - need help

    Hi. I'm trying to build a form that redirects to a page extension matching an input value. (Looking at my code will probably make that more clear.)

    When I click on my submit button, nothing happens. Can anybody help? Thanks!

    I have this short script in the <head>

    <script>
    function sendit(){
    point = document.ProfitPoint.code.value.toLowerCase()
    window.location(" 'http://blurrline.com/'+point+'/htm' "
    }
    </script>

    My url's are case sensitive, so I need the lowercase conversion.

    Here's the form code that's in the <body>

    <form name="ProfitPoint">
    Enter Code:
    <input type="text" name="code" size="15">
    <input type="button" value="Submit" onClick="sendit()">
    </form>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's because your code is a mangled, inaccessible, vastly over-complicated mess.
    Code:
    <form action="" method="get" onsubmit="this.action = this.elements['code'].value.toLowerCase(); return true;">
      <fieldset>
        <legend>Code entry form</legend>
        <input type="text" name="code" id="code" size="15">
        <label for="code">Enter Code:</label>
        <input type="submit" value="Submit">
      </fieldset>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    And, here I thought it just needed a tweak. Thanks!

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No problem
    Oh, for future reference:
    1) input type="submit" is more accessible than input type="button", and should be used where possible;
    2) same for onsubmit vs. onclick;
    3) the type attribute of the script element is required, as are action and method for form;
    4) labels are greatly superior to any other methods of labelling an element, and also produce cleaner markup;
    5) window.location is a property, not a method; direct setting should really be done using window.location.href;
    6) you only need to enclose strings in one set of quotes;
    7) you should always use the document.forms collection to reference forms, rather than assuming that they will always be available as properties of the same name under document.

    The fieldset wasn't really necessary, but I have a tendency to overdo things.
    Last edited by Twey; 05-06-2006 at 06:39 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    With trepidation...

    It's redirecting to this extension: menu?code=menu

    I'm working off of a static html page and want it to redirct to "http://blurrline.com/"+code+".htm"

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Apologies, I missed the .htm extension. You can safely ignore the question mark and everything after it; if you're using a static page, it will have no effect whatsoever.
    Code:
    <form action="" method="get" onsubmit="this.action = 'http://blurline.com/' + this.elements['code'].value.toLowerCase() + '.htm'; return true;">
      <fieldset>
        <legend>Code entry form</legend>
        <input type="text" name="code" id="code" size="15">
        <label for="code">Enter Code:</label>
        <input type="submit" value="Submit">
      </fieldset>
    </form>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks. I really appreciate the fast help. And the lessons.

    I self-taught html, but this is tougher.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I self-taught html, but this is tougher.
    Yeah... I started that way myself. You go along, thinking you know everything, then you step out into the world and find that just because it looks OK when you view it, doesn't mean it's a good page. There are these things called "standards" to adhere to, that make your page work in other browsers, and the way you've been doing everything for three years is painfully, humiliatingly, and undeniably wrong.

    Sorry, I'm in a strange mood today.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •