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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script works in IE7, not Firefox 2.0?

Status
Not open for further replies.

Arzo2000

Programmer
Jul 7, 2005
12
CA
I have the following script which is suppose to grab all parameters (and their values) passed in through query string, put them in an array, and display the parameter value in any text field on a page that has its "title" attribute the same as the parameter name.

The problem is that this script only works in IE and not Firefox. Is there a way to make it compatible for both? Or is there a function that I am using in this script that does not work in FF?

Any help is greatly appreciated guys. Thanks in advance.

Code:
	// GET AN ARRAY OF PASSED PARAMETERS...
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			qsParm[key] = val;
		}
	}

	// GET ALL ELEMENTS ON HTML DOCUMENT...
	var elementColl = document.body.all;
	var i;
	for (i = 0; i < elementColl .length; i++)
	{
		if (elementColl[i] != null && elementColl[i].getAttribute("title") != null) 
		{
			// CHECK IF PASSED PARAMETER [ARRAY KEY]  MATCHES A TITLE ATTRIBUTE ON ONE OF THE HTML ELEMENTS...
			var x = elementColl[i].getAttribute("title");
			if (qsParm[x] != null)
			{
				// SET THE ELEMENT VALUE TO THE PARAMETER VALUE [ARRAY VALUE]...
				elementColl[i].value = qsParm[x];
				//elementColl[i].parentNode.parentNode.parentNode.style.display = "none";
			}
		}
	}
 
Thanks kaht for pointing that out. I guess I can use getElementsByTagName instead. But the problem is that I need to grab more than one type of element (i.e input, textarea, and select). Is there a way to grab multiple element types through another function? Or should I go the painful path and start using a set of arrays (an array for each element type)?

Thanks again.
 
By any chance are all the elements you're wanting to loop thru in 1 form? If so, you can use the elements collection to access them:
Code:
var elementColl = document.forms["formName"].elements

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
As a matter of fact, yes! They are all in one form. I gave that shot and it did the trick.

Thanks kaht!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top