SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form submit URL redirection

    I am attempting to capture what users are searching for in a small search engine I am writing for a project.

    My idea was to place a onsubmit in the form that calls a function to grab the variables from the form, and then forward out to a new url that uses those passed variables.

    [html]
    Code:
    <form action="test.php" method="get" onsubmit="staticSearch(this);" id="search"><input type="text" name="s" id="s" value="<?php echo $_GET['s']; ?>" width="40" /><input type="hidden" name="cat" value="search" /><input type="submit" name="submit" value="Search" /></form>
    [js]
    Code:
    <script type="text/jscript">
    function staticSearch(form) {
        var s = $('s');
    	alert(s);
    	s.replace(/ /g, "-")
    	form.action = 'http://www.domain.net/marketplace/search/' + s;
    }
    </script>
    Nothing is working, not even the alert prompt. I am using the prototype library too.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The text/jscript is causing a problem. text/javascript will work there instead

    You should note that text/javascript has been officially deprecated, because it's not an occifially accepted type.
    The one to use instead is application/javascript, but IE6 doesn't understand that and ignores the script.

    So, the best practice is to use no type attribute at all. The script tag automatically defaults to javascript.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should note that text/javascript has been officially deprecated
    I couldn't believe this, so I checked, and it's true! However,
    the best practice is to use no type attribute at all
    goes against the W3C as well, as type is a required attribute of the script tag - see http://www.w3.org/TR/html401/interac...ef-type-SCRIPT

    So, there appears to be no way to conform with W3C AND support IE6 at the same time. Other than using type="text/javascript" (obsolete). So, I will keep doing that for now.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,712
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jimfraser View Post
    So, there appears to be no way to conform with W3C AND support IE6 at the same time. Other than using type="text/javascript" (obsolete). So, I will keep doing that for now.
    For me it comes down to choosing to follow the HTML 4.01 recommendation from December 1999, or RFC 4329 from April 2006.

    If anyone expresses specific inclinations to requiring strict validation, then I'm happy to keep using the obsolete text/javascript parameter. Otherwise though, because the preferred application/javascript kills IE6, I'm happy to know that I'm doing a better thing by leaving it off.
    Last edited by paul_wilkins; Mar 3, 2008 at 15:38.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Evangelist bradical1379's Avatar
    Join Date
    Feb 2007
    Posts
    443
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I got it working across all browsers.

    http://www.v6performance.net/marketplace/

    [use the search function]


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
  •