PDA

View Full Version : Help with Select Box


Dalziel
02-09-2003, 11:25 PM
This script seems to work but I get an error from the validation of the input box, it should either:

- Allow you through (if you pick an engine and a search term)
- Block you for picking an engine but no search term (that works)
- Block you for entering a search term and no engine (error)
- Block you for not picking either (error)


<html>
<head>
<title></title>
<link rel="stylesheet" href="main.css" type="text/css" />
<script language="javascript" type="text/javascript">
var site1='http://www.active7.com/srch?msx=';
var site2='http://www.alltheweb.com/search?cat=web&cs=utf-8&l=any&q=';
var site3='http://www.alltheweb.com/search?cat=img&cs=utf-8&q=';
var site4='http://uk.altavista.com/q?pg=q&q=';
var site5='http://www.altavista.com/sites/search/res_text?q=';
var site6='http://search.yahoo.com/bin/search?p=';

function ssite()
{
var url = document.sform.site.options[document.sform.site.selectedIndex].value;
url = eval(url) + document.sform.sturm.value;
A = 0;
B = 0;
C = 0;

if (document.sform.sturm.value == "")
{
A++;
}

if (document.sform.site.options[document.sform.site.selectedIndex].value == "search")
{
B = 2;
}

C = A + B;
iferror = "\n\nIf you think you have received this message in error please contact webmaster@searcharoo.cjb.net and describe the circumstances of this message appearing as best as possible.";

switch (C)
{
case 1:
alert("ERROR:\n\nYou did not enter a search term, therefore there is nothing for us to search for. Please enter a search term then try again." + iferror);
break;
case 2:
alert("ERROR:\n\nYou did not select a search engine to search, please select a search engine from our dropdown list then try again." + iferror);
break;
case 3:
alert("ERROR:\n\nYou did not enter a search term or select a search engine to use, please select a search engine and enter a search term then try again." + iferror);
break;
default:
top.window.location.href = url;
break;
}

}
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
if (isNav)
{
document.captureEvents(Event.KEYPRESS);
}
document.onkeypress = handlerKP;
function handlerKP(e)
{
kp = (isNav) ? e.which : event.keyCode
if (kp==13) ssite()
}
</script>
</head>
<body>
<form name="sform" onsubmit="return false">
<input type="text" name="sturm">
<select name="site" size="1">
<option value="search">Search Engine!</option>
<option value="site1">Active7</option>
<option value="site2">Alltheweb</option>
<option value="site3">Alltheweb (Images)</option>
<option value="site4">Altavista</option>
<option value="site5">Altavista (Text)</option>
<option value="site6">Yahoo</option></select>
<input type="button" value="Search" onclick="javascript::ssite();">
</form>
</body>
</html>

justame
02-09-2003, 11:33 PM
dal...
/me doesnt just a do® this stuff...
'cept thisss part of your 'form submit' looks just a bit® funny...
<input type="button" value="Search" onclick="javascript::ssite();">

ummm /me cant just a recall® seeing the :: before...:O(((

Dalziel
02-09-2003, 11:39 PM
it wasnt that the forum did that for some reason, its sorted now, thanks anyway

arnyinc
02-10-2003, 01:56 PM
I just reordered some stuff in the javascript:


<script language="javascript" type="text/javascript">
var site1='http://www.active7.com/srch?msx=';
var site2='http://www.alltheweb.com/search?cat=web&cs=utf-8&l=any&q=';
var site3='http://www.alltheweb.com/search?cat=img&cs=utf-8&q=';
var site4='http://uk.altavista.com/q?pg=q&q=';
var site5='http://www.altavista.com/sites/search/res_text?q=';
var site6='http://search.yahoo.com/bin/search?p=';

function ssite()
{
A = 0;
B = 0;
C = 0;

if (document.sform.sturm.value == "")
{
A++;
}

if (document.sform.site.options[document.sform.site.selectedIndex].value == "search")
{
B = 2;
}
else
{
var url = document.sform.site.options[document.sform.site.selectedIndex].value;
url = eval(url) + document.sform.sturm.value;
}

C = A + B;
iferror = "\n\nIf you think you have received this message in error please contact webmaster@searcharoo.cjb.net and describe the circumstances of this message appearing as best as possible.";

switch (C)
{
case 1:
alert("ERROR:\n\nYou did not enter a search term, therefore there is nothing for us to search for. Please enter a search term then try again." + iferror);
break;
case 2:
alert("ERROR:\n\nYou did not select a search engine to search, please select a search engine from our dropdown list then try again." + iferror);
break;
case 3:
alert("ERROR:\n\nYou did not enter a search term or select a search engine to use, please select a search engine and enter a search term then try again." + iferror);
break;
default:
top.window.location.href = url;
break;
}

}
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
if (isNav)
{
document.captureEvents(Event.KEYPRESS);
}
document.onkeypress = handlerKP;
function handlerKP(e)
{
kp = (isNav) ? e.which : event.keyCode
if (kp==13) ssite()
}
</script>

top500
02-10-2003, 02:17 PM
yeyo.

<input type="button" value="Search" onclick="ssite()">

try that :-)