Click to See Complete Forum and Search --> : form field value passed to hyperlink


nightrider
08-21-2003, 06:29 AM
Hello People,
Don't know much about javascript so here is a simple question.

I have a form field called search. I have also created a few hyperlinks with url pointing to different search engines. When I put the search keyword in the form field and then click on a link I want that value to be passed to the variable in the hyperlink.

How can this be achieved.

Example
form field_name =search_field
value = javascript

Links
1. Google link url = http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=javascript
2. Lycos link url = http://search.lycos.com/default.asp?lpv=1&loc=searchhp&tab=web&query=javascript

I want the javascript value to be derived from the search_field value when I click on each of the links.

Please help
Thanks

Khalid Ali
08-21-2003, 08:05 AM
you will need to retrieve the text field or selection box value onclick event of the link.
onclick="this.href = this.href+'?'+this.form.fieldName.value"

the above is an idea hwo you can do this.

nightrider
08-22-2003, 04:35 AM
Thanks for the answer. I have managed to get that working. However,\I have another problem. If i type in a value in the search field and click the url it works first time. If I then erase the value form the search field and enter another field then the url seems to append the new search value to the old value.

i.e if the entered 'hello' in search field and clicked url
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=hello will appear.

if i then ease the search field and enter a new value 'world' it also retains the old value so the url now shows
http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=helloworld

code looks a bit like the below.

<a href="http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=" onClick="this.href = this.href+''+document.form1.text.value+'';" target="middle">


any help will be appreciated.