SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto Quotes in forms

    I am putting a search engine on a website. I can either use JS or xhtml but in order to get a correct return I need to automatically put quotes around the input. It is a golf site and will be large. If someone searched for "golf clubs" it would show 4 articles which is the correct amount. If the searched for golf clubs without the quotes everything in the site will show up and that could be as many as 500 articles. I know even if i asked them to put quotes around their search phrase many will not. How can I have the quotes automatically entered around the search term?
    Thank you
    Don Young

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You'll have to use javascript for this. Something like this:
    HTML Code:
    <form id="aform" method="get" action="golf.php">
    <input type="text" name="keywords" />
    <input type="button" id="submit" value="Go" />
    </form>
    Then in your JS you put:
    Code:
    document.getElementById('submit').onclick = function () {
      var keywords = '"' . document.getElementByName('keywords').value . '"';
      document.getElementByName('keywords').value = keywords;
      document.getElementById('aform').submit();
    }
    There may be a better way to do it though, but that's how I would do it.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Raffles, there is no document.getElementByName() function. You probably want document.getElementsByName().

    Code:
    document.getElementsByName('keywords')[0]
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Whoops, that's what I meant. Cheers Kravvitz.

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys

  6. #6
    Guru Meditation Error gnarly's Avatar
    Join Date
    Dec 2003
    Location
    Cheltenham, United Kingdom
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not that'll only work if they have javascript enabled. You'd be much better off handling this on the server side. Also, that script doesn't take into account and "" they've added already.
    Olly Hodgson
    thinkdrastic.net


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
  •