...

View Full Version : Form addition



StillLearning
09-08-2006, 11:56 PM
I have been playing around with this working code:

<script language="JavaScript" type="text/javascript">
<!--
function search_google(){
window.open("http://www.google.com/search?q="+document.search.query.value);
}
//-->
</script>
<form name="search">
<input type="text" name="query" value="">
<input type="submit" value="Search Google" onClick="search_google()">
</form>

If I type for example 'feet' into the form it produces the query string
http://www.google.com/search?q=feet which is fine but ....

I would like to modify the script to produce a query string like this
http://www.google.com/search?q=feet+site%3Amyfootshop.com with the additional text provided by a hardcoded variable such as additionaltext=+site%3Amyfootshop.com

I know it must be quite easy but I am new to JavaScript.

Thank you for any help.

_Aerospace_Eng_
09-09-2006, 12:37 AM
PHP would be better for this as it has a url_encode function. Why the need for javascript? Can you not run php on your server?

Basscyst
09-09-2006, 01:19 AM
Javascript does too.



encodeURIComponent("feet and hands")


Basscyst

StillLearning
09-09-2006, 06:16 AM
How would I use the encodeURIComponent to concatenate the form input with a variable as above?

Thanks.

_Aerospace_Eng_
09-09-2006, 07:07 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function search_google(){
var x = encodeURIComponent(document.search.query.value)
window.open("http://www.google.com/search?q="+x);
return false;
}
//-->
</script>
</head>
<body>
<form name="search" onSubmit="return search_google()">
<input type="text" name="query" value="">
<input type="submit" value="Search Google">
</form>
</body>
</html>

StillLearning
09-09-2006, 09:01 AM
Thank you very much for the help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum