Click to See Complete Forum and Search --> : javascript form help


chipdouglas2819
March 12th, 2006, 08:11 PM
how would you make a snippit that u insert it and it will have a single text box and u type in waht u want to search there, check boxes that say google, msn, yahoo, ect. that if selected will open a new window of the search of those sites. (i want each one to be a different window of each website its searching) how would i go about making this?

-- i found something simalar to what i want here: http://www.javascriptkit.com/script/...e_search.shtml

but i still want it to be a check box and for each one is a new window and on that it searches the specific site i want to be able to search all of the web and have another check box that will search the page

PeejAvery
March 13th, 2006, 09:50 AM
but i still want it to be a check box and for each one is a new window and on that it searches the specific site i want to be able to search all of the web and have another check box that will search the page
Make the checkboxes an array and just use a for loop to open a new window. I can write and example later when I have time.

degsy
March 14th, 2006, 11:04 AM
There are several ways to do it. Here is an example


<!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>Untitled Document</title>
<script type="text/javascript">
function goSearch(frm){
err = '';
count = 0;

if(frm.st.value == ""){
err += "Please enter a search term\n";
}

for(x=0; x<frm.se.length; x++){
if(frm.se[x].checked == true){
if(frm.st.value != ""){
switch(frm.se[x].value){
case 'google':
url = 'http://www.google.co.uk/search?hl=en&q=' + frm.st.value;
window.open(url);
break;
case 'yahoo':
url = 'http://search.yahoo.com/search?p=' + frm.st.value;
window.open(url);
break;
case 'msn':
url = 'http://search.msn.com/results.aspx?q=' + frm.st.value;
window.open(url);
break;
}
}
count++;
}
}

if(count == 0){
err += "Please choose at least one search engine\n";
}

if(err != ""){
alert(err);
return false;
}
return false;
}
</script>
</head>

<body>
<form name="form1" method="post" action="" onsubmit="return goSearch(this)">
<p>
Search Terms
<br>
<input name="st" type="text" id="search">
</p>
<p>Search Engines<br>
<input name="se[]" type="checkbox" id="se" value="google">
Google<br>
<input name="se[]" type="checkbox" id="se" value="yahoo">
Yahoo<br>
<input name="se[]" type="checkbox" id="se" value="msn">
MSN
</p>
<p>
<input type="submit" name="Submit" value="Search">
</p>
<p>&nbsp; </p>
</form>
</body>
</html>

chipdouglas2819
March 14th, 2006, 04:19 PM
thx, i played around with it a little and its lookin good :-D