Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript works in IE8/IE9 not Chrome

Status
Not open for further replies.

gamc2

Programmer
Aug 2, 2012
2
US
This function works in IE8/9. It fails in CHROME. See error below.


function runSearch() {

var tmptarget = (document.forms(0).target);

Error returned by CHROME --->
Uncaught TypeError: Property 'forms' of object #<HTMLDocument> is not a function

Additional lines of code below:

var tmpaction = (document.forms(0).action);

document.forms(0).action = "SSearch.aspx?SEARCHTYPE=" + encodeURI(document.getElementById("SSearchType").options[document.getElementById("SSearchType").selectedIndex].value) + "&SSEARCHVALUE=" + encodeURI(document.getElementById("SSearchValue").value);
document.forms(0).target = "_self";
document.forms(0).submit();
document.forms(0).target = tmptarget;
document.forms(0).action = tmpaction;
}


Any help would be great! I need to know what to do to make
this run in both IE and CHROME.


gamc2
 
Hi

[tt]document.forms[/tt] is an object of [tt]HTMLCollection[/tt] class, not a method. So you can not call it.

To access an item of the collection by its index, specify it in brackets :
JavaScript:
[gray]// wrong[/gray]
[s]document[teal].[/teal][COLOR=darkgoldenrod]forms[/color][teal]([/teal][purple]0[/purple][teal]).[/teal]target[/s]

[gray]// correct[/gray]
document[teal].[/teal]forms[teal][[/teal][purple]0[/purple][teal]].[/teal]target


Feherke.
[link feherke.github.com/][/url]
 
Thank you very much for the help. This fixed the problem!

gamc2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top