Javascript Getelementsbytagname Array

by admin on October 10, 2010

javascript getelementsbytagname array

javascript getelementsbytagname array Questions


Javascript Radio button checker?

I’m having trouble making a script that creates a array for all radio buttons on a page and then checks them. This is what I have so far.

var radbuttons = document.getElementsByTagName(‘radio’);
for (var i = 0; i < radbuttons.length; i++)
{
radbuttons[i].checked
}

Where did I go wrong?

The tag name is actually ‘input’ not radio. So that should probably not work. I would be surprised if it did.

There are a couple of different things you could do here, but this is probably the most straightforward.

var inputs = document.getElementsByTagName(‘input’);
for (var i = 0; i < inputs.length; i++)
{

if(inputs[i].type = = "radio"){
inputs[i].checked = true;
}

}

You can also give the radios the same name, name="myradio" and then access that with getElementsByName() or, document.yourformname.myradio[i]

It seems there should be such a method as getElementsByType().. But I've never heard of such.

Good luck.

javascript getelementsbytagname array Videos

Universidade XTI – JavaScript – 35. Funções de CallBack

It has never been easier to shop for javascript getelementsbytagname array,

So run don”t walk and pick up javascript getelementsbytagname array at bargain

prices!

Leave a Comment

Next post: