document.all and document.getElementById

D

dal.luc

Hello,

I've a problem : I want to check which element has been checked in a
list of radiobuttons.

/////////////////////////////////////
function numeroChk(liste)
{
var elem=document.all(liste)
alert(elem.length)
for(i=0;i<elem.length;i++)
{
if (elem.checked)
{
indice = elem.value;
return indice;
}
}
}

This work fine in IE but not in Firefox
The problem is that document.all is not recognized by Firefox, but when
I try document.getElementById(liste), nothing works

liste is a string.

What must I do to translate this function properly ?

Thanks for assistance

Luc
 
E

Erwin Moller

Hello,

I've a problem : I want to check which element has been checked in a
list of radiobuttons.

/////////////////////////////////////
function numeroChk(liste)
{
var elem=document.all(liste)
alert(elem.length)
for(i=0;i<elem.length;i++)
{
if (elem.checked)
{
indice = elem.value;
return indice;
}
}
}

This work fine in IE but not in Firefox
The problem is that document.all is not recognized by Firefox, but when
I try document.getElementById(liste), nothing works

liste is a string.

What must I do to translate this function properly ?

Thanks for assistance

Luc


Hi,

Never use document.all since it is IE only.
Just name your form and use:
var radiogroup = document.forms["FORMNAMEHERE"].RADIONAMEHERE;

Works everywhere for many years. :)

Regards,
Erwin Moller
 
D

dal.luc

Thanks
Works fine



Erwin Moller a écrit :
Hello,

I've a problem : I want to check which element has been checked in a
list of radiobuttons.

/////////////////////////////////////
function numeroChk(liste)
{
var elem=document.all(liste)
alert(elem.length)
for(i=0;i<elem.length;i++)
{
if (elem.checked)
{
indice = elem.value;
return indice;
}
}
}

This work fine in IE but not in Firefox
The problem is that document.all is not recognized by Firefox, but when
I try document.getElementById(liste), nothing works

liste is a string.

What must I do to translate this function properly ?

Thanks for assistance

Luc


Hi,

Never use document.all since it is IE only.
Just name your form and use:
var radiogroup = document.forms["FORMNAMEHERE"].RADIONAMEHERE;

Works everywhere for many years. :)

Regards,
Erwin Moller
 
M

mick white

Hello,

I've a problem : I want to check which element has been checked in a
list of radiobuttons.

/////////////////////////////////////
function numeroChk(liste)
{
var elem=document.all(liste)
alert(elem.length)
for(i=0;i<elem.length;i++)
{
if (elem.checked)
{
indice = elem.value;
return indice;
}
}
}


function numeroChk(liste){
var elem=document.forms[0].liste,eL=elem.length;
if(eL){
for(var i=0;i<eL;i++){
if (elem.checked){
return elem.value;
}
}
}
return "Oops"
}

Mick
 
J

Jonas Raoni

mick white escreveu:
(e-mail address removed) wrote:
function numeroChk(liste){
var elem=document.forms[0].liste,eL=elem.length;

This is not the desired effect, "liste" is an argument, not the input name.
if(eL){
for(var i=0;i<eL;i++){
if (elem.checked){
return elem.value;
}
}
}
return "Oops"
}



If it's a dynamic checkbox, it's possible that just one item will be
outputed, so the "form.liste" won't be a NodeList, but a simple Element,
in this case, instead of return "Oops" you should do a simple check.

//I don't like "getElementsByName", but for this case, it's what better
match the sender code.

function numeroChk(liste){
for(var o = document.getElementsByName(liste), i = o.length; i--;)
if(o.checked)
return o.value;
return null;
}
 

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
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top