dcsimg
Problem with form id instead of form name in XHTML strict document
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   mark_henderson
Posted On:   Thursday, August 28, 2003 04:25 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 unacce   More>>

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



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;

}

// etc etc



location.href = finalSearchString;

}

}







All help greatly appreciated.

regards

Mark H

   <<Less

Re: Problem with form id instead of form name in XHTML strict document

Posted By:   Nitesh_Naveen  
Posted On:   Friday, August 29, 2003 02:23 AM

Well... things may work out with Netscpae 6+. use document.getElementById there. But you can't expect XHTML complaincy with Netscpae 4.7x browsers which came before XHTML stipulations evolved. Just a question... can't you keep the name as well as the id for the form so that it works fine with all browsers???
About | Sitemap | Contact