How do I get text from a url to my search form?

Discussion in 'HTML & Website Design' started by Red Paul, Jan 14, 2008.

  1. #1
    What I want to do is put links on my site that automatically fill in search text....

    e.g. instead of the user typing 'tuners' in the search box an pressing enter, I want a link that says 'Search for all Tuners' and when they click it it does the search. Is there an easy way to pass text to the search function?

    OK, so my search form looks like this:

    Quote:
    <FORM NAME="quick_find" ACTION="index.asp?function=SEARCH" METHOD="POST">

    I'm a bit of a numptie on such things, so treat me like an idiot! :eek:

    Thanks,
    RP
     
    Red Paul, Jan 14, 2008 IP
  2. rkquest

    rkquest Well-Known Member

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    140
    #2
    You should've posted this in the Javascript forum.

    Anyway, try this one..

    
    <script type="text/javascript">
    function quickFind(query) {
    	document.quick_find.query.value=query; 	
    	document.quick_find.submit();
    }
    </script>
    
    <form name="quick_find" action="index.asp?function=SEARCH" method="POST">
    <input type="text" name="query" /><input type="submit" value="Search" />
    </form>
    
    <a href="javascript:quickFind('tuners');">Search for all Tuners</a>
    
    HTML:
    You didn't say what the name of the text field is so I just used "query".. but you can change that to whatever yours is. You'll have to change the one in the script as well.
     
    rkquest, Jan 15, 2008 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Or you can do it serverside instead so it works for users who have javascript turned off....

    For ASP/ ASP.Net it would simply be a case of having Request.Querystring("ID of Attribute") to pick up the value from the URL and then feed this into your normal search script
     
    AstarothSolutions, Jan 15, 2008 IP
  4. Red Paul

    Red Paul Peon

    Messages:
    115
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Red Paul, Jan 15, 2008 IP