Brutality
08-28-2003, 05:56 PM
Recently I updated our homepage to xhtml 1 strict. However, this document type requires forms to use ID's instead of names, and as a result has caused a problem with one script running on the site.
Script in question can be found at the top (WWW search script)
http://www.cwc.co.nz/scripts/global.js
and is obviously related to the search that resides top left on the site http://www.cwc.co.nz
The basic problem is this - the script originally uses document.search.searchtext.value to acess the value entered, but of course this requires the form to have a name. I removed the 'document' part, leaving
search.searchtext.value, and this works in IE and Opera, but not Mozilla and NS, so this is unacceptable to me (but not my boss)
The question. Is there anyway of using formobj.form[] or some other method to access the form without needing a name?
Heres the script
/////////////////////
//WWW SEARCH FUNCTION
/////////////////////
function startSearch(){
searchString = document.search.searchtext.value;
if(searchString != ""){
searchEngine = document.search.whichEngine.selectedIndex + 1;
finalSearchString = "";
if(searchEngine == 1){
finalSearchString = "http://www.google.co.nz/search?q=" + searchString + "&hl=en&lr=";
}
if(searchEngine == 2){
finalSearchString = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=" + searchString;
}
if(searchEngine == 3){
finalSearchString = "http://av.yahoo.com/bin/query?p=" + searchString + "&hc=0&hs=0";
}
if(searchEngine == 4){
finalSearchString = "http://www.hotbot.com/?SW=web&SM=MC&MT=" + searchString + "&DC=10&DE=2&RG=NA&_v=2&act.search.x=89&act.search.y=7";
}
if(searchEngine == 5){
finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?adv=%26adv%3B&cat=lycos&matchmode=and&query=" + searchString + "&x=45&y=11";
}
if(searchEngine == 6){
finalSearchString = "http://www.searchnz.co.nz/cgi-bin/search?q=" + searchString + "&fm=&gr=";
}
if(searchEngine == 7){
finalSearchString = "http://www.yellowpages.co.nz/quick/search?key=" + searchString + "&lkey=&stype=&search.x=0&search.y=0";
}
if(searchEngine == 8){
finalSearchString = "http://www.cwc.co.nz/cgi-bin/ksearch/ksearch.pl?searchtext=" + searchString + "&all=1&c=0&w=s&st=s&sort=Matches&display=5&b=1&t=1&u=1&alt=1&l=1&default=1&d=1&k=1&au=1";
}
location.href = finalSearchString;
}
}
All help greatly appreciated.
regards
Mark H
Script in question can be found at the top (WWW search script)
http://www.cwc.co.nz/scripts/global.js
and is obviously related to the search that resides top left on the site http://www.cwc.co.nz
The basic problem is this - the script originally uses document.search.searchtext.value to acess the value entered, but of course this requires the form to have a name. I removed the 'document' part, leaving
search.searchtext.value, and this works in IE and Opera, but not Mozilla and NS, so this is unacceptable to me (but not my boss)
The question. Is there anyway of using formobj.form[] or some other method to access the form without needing a name?
Heres the script
/////////////////////
//WWW SEARCH FUNCTION
/////////////////////
function startSearch(){
searchString = document.search.searchtext.value;
if(searchString != ""){
searchEngine = document.search.whichEngine.selectedIndex + 1;
finalSearchString = "";
if(searchEngine == 1){
finalSearchString = "http://www.google.co.nz/search?q=" + searchString + "&hl=en&lr=";
}
if(searchEngine == 2){
finalSearchString = "http://www.altavista.digital.com/cgi-bin/query?pg=q&what=web&fmt=.&q=" + searchString;
}
if(searchEngine == 3){
finalSearchString = "http://av.yahoo.com/bin/query?p=" + searchString + "&hc=0&hs=0";
}
if(searchEngine == 4){
finalSearchString = "http://www.hotbot.com/?SW=web&SM=MC&MT=" + searchString + "&DC=10&DE=2&RG=NA&_v=2&act.search.x=89&act.search.y=7";
}
if(searchEngine == 5){
finalSearchString = "http://www.lycos.com/cgi-bin/pursuit?adv=%26adv%3B&cat=lycos&matchmode=and&query=" + searchString + "&x=45&y=11";
}
if(searchEngine == 6){
finalSearchString = "http://www.searchnz.co.nz/cgi-bin/search?q=" + searchString + "&fm=&gr=";
}
if(searchEngine == 7){
finalSearchString = "http://www.yellowpages.co.nz/quick/search?key=" + searchString + "&lkey=&stype=&search.x=0&search.y=0";
}
if(searchEngine == 8){
finalSearchString = "http://www.cwc.co.nz/cgi-bin/ksearch/ksearch.pl?searchtext=" + searchString + "&all=1&c=0&w=s&st=s&sort=Matches&display=5&b=1&t=1&u=1&alt=1&l=1&default=1&d=1&k=1&au=1";
}
location.href = finalSearchString;
}
}
All help greatly appreciated.
regards
Mark H