Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 635
Trades: 0
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?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
 
Register now for full access!
Old 11-02-2006, 03:04 PM Re: Joining arrays of elements...
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
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.

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 Search this Thread
Search this Thread:

Advanced Search

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

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





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



Page generated in 0.10426 seconds with 12 queries