Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically Change the hyperlink based on the keywords entered. 1

Status
Not open for further replies.

Nrupesh

Technical User
May 9, 2002
1
CN
Hi guyz,

I am trying to come up with something like but for my own convenience as we have to go through a lot of websites daily to search for info and this would save me a lot of time.
Basically , like turboscout.com, I want to search 5 of my sites by putting the info from the textbox into the hyperlinks automatically.

What I will have is a page with certain links on it for different sites, for example on the top of the page will be a textbox and below it there will be a few sites like for example.
Now when I put the keywords "puppy food" in the textbox and click on Petco.com , it should go to
I am quite familiar with HTML but I suck at programming, so any starting tips would be appreciated.... I know this shouldn't be a lot of work and there might be some script already out there, but I looked for a few hours before I am asking here.

Thanks a lot for any help... will be very appreciated!

Regds,

Nrupesh
nrupesh(at)usa.net
 
First, do all the sites you want to search accept the search terms on the URL and if so, do they use the same variable name in the URL?

In general what you would do would go like this.
Have an onclick event in your link that would execute a javascript function and in that function do this:
1. Grab the value of the text box containing the search terms.
2. URLEncode the search terms string so things like spaces will not break the URL.
3. Update the URL in the link that called the function with a URL containing the terms.
4. Return true to the link function so that it will continue executing the hyperlink.

The other option would be to enter your search terms on one page then generate the links based on those terms when you submit returning you a page with the appropriate links.


Paranoid? ME?? Who wants to know????
 
it seems to me that something like this would probably be the easiest way to accomplish what you are wanting:
Code:
<html>
<head>
</head>
<body>
<form name="Site_Search_Form" action=".">
<input name="t"><br>
</form>
<a href="." onClick="document.Site_Search_Form.action = '[URL unfurl="true"]http://www.petco.com/Shop/SearchResu...';[/URL] document.Site_Search_Form.submit(); return false;">Petco.com</a><a href="." onClick="document.Site_Search_Form.action = '[URL unfurl="true"]http://www.wherever.com/Shop/SearchResu...';[/URL] document.Site_Search_Form.submit(); return false;">Wherever.com</a>
</body>
</html>



I hope this helps;
Rob Hercules
 
Hi Rob,
I've tried several derivations of the petco search with no success. Would you be so kind as to explain how this should work. Comparing the addresses that the actual petco search returns, the petco site appears to add quite a bit of information in the return address that would not be know to the user...

Thanks,
George
 
Code:
[tt]<form name="Site_Search_Form" action="." method=GET>
<input name="t"><br>
[COLOR=blue]             ^--insert the operator here (ex. [URL unfurl="true"]http://www.whatever.com/search.php&[/URL][i][COLOR=red]operator[/color][/i]=something[/color]
</form>
<a href="." onClick="document.Site_Search_Form.action = '[URL unfurl="true"]http://www.petco.com/Shop/SearchResu...';[/URL]
[COLOR=blue]  ^--insert search page URL here (ex. [COLOR=red][i][URL unfurl="true"]http://www.whatever.com/search.php[/URL][/i][/color])[/color]
document.Site_Search_Form.submit(); return false;">Petco.com</a>[/tt]

If you code it as I've directed above for each site, then when a user clicks the link for that site, they should be directed to the URL: whatever[ignore]%20they%20typed%20in%20the%20search%20box[/ignore]



I hope this helps;
Rob Hercules
 
Hi Rob,
I'm still having problems...
Given the following code, and many different iterations - I'm not successfully querrying the petco site.
Code:
<html>
<head>
</head>
<body>
<form name="Site_Search_Form" action=".">
<input name="t"><br>
</form>
<a href="." onClick="document.Site_Search_Form.action = '[URL unfurl="true"]http://www.petco.com/Shop/SearchResults.aspx?operator';[/URL] document.Site_Search_Form.submit(); return false;">Petco.com</a><br />
<a href="." onClick="document.Site_Search_Form.action = '[URL unfurl="true"]http://www.wherever.com/Shop/SearchResu...';[/URL] document.Site_Search_Form.submit(); return false;">Wherever.com</a>
</body>
</html>

I get back..
(which brings back all 4000+ possibilities - not limited to collars)

whereas the search from the petco site for collars gives..

Any other clues to help would be greatly appreciated.

Thanks,
George
 
OK, that seems to be a critical bit of information that I was unaware of there.

OK, I personally tested this one and it DOES work:
Code:
<html>
<head>
</head>
<body>
<form name="Site_Search_Form" action="." onSubmit="return false;">
<input name="t"><br>
</form>
<a href="." onClick="document.location.href = '[URL unfurl="true"]http://www.petco.com/Shop/SearchResults.aspx?Nav=1&;N=0&Ntt='[/URL] + document.Site_Search_Form.t.value; return false;">Petco.com</a>
</body>
</html>

You'll just have to replace [tt][ignore][/ignore][/tt] with whatever shows up in the URL before the search query name on the other sites.

Let me know if that fixes it for you.



I hope this helps;
Rob Hercules
 
Works nicely,
Not sure what the onSubmit = "return false is doing"

Thanks, George
 
the [tt]onSubmit="return false;"[/tt] just keeps the form from submitting (which would really just refresh the page & delete the search term the user entered in this case) if the user accidentally presses the "return" or "enter" key. With the "return false;" in there, it tells the browser that if the form tries to submit itself, don't let it.



I hope this helps;
Rob Hercules
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top