Hi I've had this script for a few years which I use to make a search box, it adds the user's search to the end of a url, so you can make a search box for Google or pretty much anything. If the user clicks on submit ('Find') without selecting a pull down option I like the script to alert something like 'select a site' or if they don't enter any keyword to alert 'enter a keyword', however when either of these happens, the alert box needs to be clicked several times to get rid of the alert. so I'm wondering if the script is running in some kind of loop.... The script does what I wat I just want to make the alert boxes go after the first 'click' to hide them... hope this makes sense here's the script, thanks for any ideas folks..
---------------------
----------------
searchdata.js
----------------
function addplus(items)
{
var plussed = "";
for (var t = 1 ; t <= items.length ; t++)
{
if (items.substring(t-1,t) == " ")
{ plussed+="+"; }
else
{ plussed+=items.substring(t-1,t); }
}
return plussed;
}
function searchdata()
{
var words;
words = document.getElementById("querydata").value;
var searchitems;
searchitems=addplus(words);
var index;
index = document.getElementById("subjectdata").selectedIndex;
collection = document.getElementById("subjectdata").value;
if (document.getElementById("subjectdata").value == "null" || document.getElementById("subjectdata").value == "")
{alert("\nSelect a site to search");}
else
{
var site;
site = document.getElementById("subjectdata").value;
site+=searchitems;
if (notEmpty(searchitems))
{
window.open("","newwin","status=0,resizable=1, menubar=1, toolbar=1, scrollbars=1, location=1, directories=0, width=900, height=600, top=200, left=200");
window.open(site,"newwin");
}
}
}
function notEmpty(word)
{
if (word == "" || word == null)
{
alert("\nEnter a keyword to search");
document.getElementById("querydata").focus();
return false;
}
else
{
return true;
}
}
-----------------------------------------------------------------
the form to display the search box
---------------------------------
<script src="searchdata.js" type="text/javascript"></script >
<form id="searchform" onsubmit="searchdata()" action="javascript:searchdata()" method="get">
<select id="subjectdata">
<optgroup>
<option select="selected" value="null">Choose coverage</option>
<option value=" Statistics</option>
<option value=" & Data on the </optgroup>
</select>
<input id="querydata" value="type here" />
<input onkeypress="searchdata()" onclick="searchdata()" type="submit" value="Find" />
</form>
---------------------
----------------
searchdata.js
----------------
function addplus(items)
{
var plussed = "";
for (var t = 1 ; t <= items.length ; t++)
{
if (items.substring(t-1,t) == " ")
{ plussed+="+"; }
else
{ plussed+=items.substring(t-1,t); }
}
return plussed;
}
function searchdata()
{
var words;
words = document.getElementById("querydata").value;
var searchitems;
searchitems=addplus(words);
var index;
index = document.getElementById("subjectdata").selectedIndex;
collection = document.getElementById("subjectdata").value;
if (document.getElementById("subjectdata").value == "null" || document.getElementById("subjectdata").value == "")
{alert("\nSelect a site to search");}
else
{
var site;
site = document.getElementById("subjectdata").value;
site+=searchitems;
if (notEmpty(searchitems))
{
window.open("","newwin","status=0,resizable=1, menubar=1, toolbar=1, scrollbars=1, location=1, directories=0, width=900, height=600, top=200, left=200");
window.open(site,"newwin");
}
}
}
function notEmpty(word)
{
if (word == "" || word == null)
{
alert("\nEnter a keyword to search");
document.getElementById("querydata").focus();
return false;
}
else
{
return true;
}
}
-----------------------------------------------------------------
the form to display the search box
---------------------------------
<script src="searchdata.js" type="text/javascript"></script >
<form id="searchform" onsubmit="searchdata()" action="javascript:searchdata()" method="get">
<select id="subjectdata">
<optgroup>
<option select="selected" value="null">Choose coverage</option>
<option value=" Statistics</option>
<option value=" & Data on the </optgroup>
</select>
<input id="querydata" value="type here" />
<input onkeypress="searchdata()" onclick="searchdata()" type="submit" value="Find" />
</form>