By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,579 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

document.all and document.getElementById

P: n/a
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[i].checked)
{
indice = elem[i].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

Nov 20 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
da*****@gmail.com wrote:
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[i].checked)
{
indice = elem[i].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
Nov 20 '06 #2

P: n/a
Thanks
Works fine

Erwin Moller a écrit :
da*****@gmail.com wrote:
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[i].checked)
{
indice = elem[i].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
Nov 20 '06 #3

P: n/a
da*****@gmail.com wrote:
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[i].checked)
{
indice = elem[i].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[i].checked){
return elem[i].value;
}
}
}
return "Oops"
}

Mick
>
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
Nov 20 '06 #4

P: n/a
mick white escreveu:
da*****@gmail.com 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[i].checked){
return elem[i].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[i].checked)
return o[i].value;
return null;
}
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Nov 21 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.