Reply
Joining arrays of elements...
Old 11-02-2006, 02:00 PM Joining arrays of elements...
funkdaddu's Avatar
Web Design Snob

Posts: 636
I'm trying to join a couple arrays of elements but it's not working - the page returns an error saying "inputsToDisable.concat() is not a function":. Here is a simple example of my script:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--

function disableInputs(el,tf) {
	var inputsToDisable = el.getElementsByTagName("input");
	var selectsToDisable = el.getElementsByTagName("select");
	var textareasToDisable = el.getElementsByTagName("textarea");
	var allFieldsToDisable = inputsToDisable.concat(selectsToDisable,textareasToDisable);
	//disable fields in hidden areas
	for (j=0;j<allFieldsToDisable.length; j++) {
		allFieldsToDisable[j].disabled = tf;
	}
}

window.onload = function() {
	disableInputs(document.getElementById("hideme"),true);
}

//-->
</script>
	</head>

	<body>
		<fieldset id="hideme">
			<legend>Legend</legend><input type="text" name="textfieldName" size="24">
			<p><select name="selectName" size="1">
					<option value="one">first</option>
					<option value="two">second</option>
					<option value="three">third</option>
				</select></p>
			<p><textarea name="textareaName" rows="4" cols="40"></textarea></p>
		</fieldset>
	</body>

</html>
I thought I was using concat wrong, but If I just use numbers instead of the element arrays it works fine:

Code:
var x = [1,2,3];
var y = [4,5,6];
var z = [7,8,9];
var a = x.concat(y,z);
alert(a);
If I use just one of the array of elements it works fine, but I want to disable all the fields inside selected elements. Can anyone help?
__________________
Will Work For Talkputation...
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
When You Register, These Ads Go Away!
Old 11-02-2006, 03:04 PM Re: Joining arrays of elements...
funkdaddu's Avatar
Web Design Snob

Posts: 636
OK, I think I see the problem, getElementsByTagName() doesn't return an "object", it returns a "function". If I use this code:
Code:
function disableInputs(el,tf) {
	var allFieldsToDisable = new Array();
	alert(typeof(el.getElementsByTagName("input")));
	var inputsToDisable = el.getElementsByTagName("input");
	var selectsToDisable = el.getElementsByTagName("select");
	var textareasToDisable = el.getElementsByTagName("textarea");
	allFieldsToDisable = allFieldsToDisable.concat(inputsToDisable,selectsToDisable,textareasToDisable);
	//disable fields in hidden areas
	for (j=0;j<allFieldsToDisable.length; j++) {
		alert(typeof(allFieldsToDisable[j]));
		allFieldsToDisable[j].disabled = tf;
	}
}
It pops up the type of the returned elements, and it is coming up as "function" instead of "object" - can anyone shed some light on this? I thought it would return an array object.
__________________
Will Work For Talkputation...

Last edited by funkdaddu : 11-02-2006 at 03:09 PM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Reply     « Reply to Joining arrays of elements...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10997 seconds with 12 queries