simple javascript help

D

dodgeyb

Hi there, javascript newbie here, having to convert my asp.net (vb)
code to client side javascript.
I have several textareas (number varies) and I need to a function to
loop through them & disable them all EXCEPT one textarea which is the
parameter passed. So the parameter passed to the function is the name
of the textarea required to stay enabled.
I have so far :

function btnSet_Click(id){

var ele = document.getElementsByTagName('textarea');
if(ele != null)
for(i=0;i<ele.length;i++)
{
if(ele(i).name==id){
ele(i).disabled=false;

}
else
ele(i).disabled=true;
}
}

The loop is working, but I'm wide of the mark on the comparison line I
think.
All help much appr'd !
Chris
 
T

Tim Slattery

dodgeyb said:
Hi there, javascript newbie here, having to convert my asp.net (vb)
code to client side javascript.
I have several textareas (number varies) and I need to a function to
loop through them & disable them all EXCEPT one textarea which is the
parameter passed. So the parameter passed to the function is the name
of the textarea required to stay enabled.
I have so far :

function btnSet_Click(id){

var ele = document.getElementsByTagName('textarea');
if(ele != null)
for(i=0;i<ele.length;i++)
{
if(ele(i).name==id){

Javascript array subscripts are delimited by square brackets,not
parentheses. So this line should be:
if (ele.name == id)
ele(i).disabled=false; ele.disabled = false;

}
else
ele(i).disabled=true; ele.disabled = true;
}
}

The loop is working, but I'm wide of the mark on the comparison line I
think.
All help much appr'd !
Chris
 
T

Thomas 'PointedEars' Lahn

Tim said:
dodgeyb said:
[...]
var ele = document.getElementsByTagName('textarea');
if(ele != null)
for(i=0;i<ele.length;i++)
{
if(ele(i).name==id){

Javascript array subscripts are delimited by square brackets,not
parentheses. [...]

These are _not_ "array subscripts" but bracket property accessors
(Flanagan's "JavaScript: The Definitive Guide" has it wrong, too.) `ele' is
_not_ a reference to an Array object; it is a reference to a *NodeList*
object. The bracket property accessor with a numeric parameter invokes the
item() method of the objects implementing the respective DOM interface:

http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html
http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html


PointedEars
 
L

Lee

Thomas 'PointedEars' Lahn said:
Tim said:
dodgeyb said:
[...]
var ele = document.getElementsByTagName('textarea');
if(ele != null)
for(i=0;i<ele.length;i++)
{
if(ele(i).name==id){

Javascript array subscripts are delimited by square brackets,not
parentheses. [...]

These are _not_ "array subscripts" but bracket property accessors
(Flanagan's "JavaScript: The Definitive Guide" has it wrong, too.) `ele' is
_not_ a reference to an Array object; it is a reference to a *NodeList*
object.

There's nothing wrong with referring to a *NodeList* object as
an array in this context. Not every array is an Array.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top