[Javascript] Radio Button Value Property Does Not Exist in Netscape 6.1?

gregory.john.toland at census.gov gregory.john.toland at census.gov
Fri Oct 26 15:15:56 CDT 2001


You are correct in your first observation.  I should have said "Tabular" is
returned by the statement:

     alert( document.MyForm.txtStep1.value );

But your last bit of code is what I am exactly referring to.  In Netscap
6.1 the code:

function getRadioVal(rb){
var L=rb.length;var ret="";
for (var i = 0 ; i< L ; i++)
 { if(rb[i].checked) { ret=rb[i].value; break; } }
return(ret);
}

does not work.  At least I cannot get it to work.  Have you tested this in
6.1?  The expression, rb.length, is "undefined" when I pass into it,
document.MyForm.txtStep1.

Gregory



>From Rodney Myers...

Gregory,

 I find the observations in your  posting disturbing.
The more so because as the 0 element is clearly marked as checked one might
expect at least that its value would be returned if a construct such as
document.MyForm.txtStep1.value is to give any value (or had you manually
checked the [1] button?)

Probably the browser anomaly will require special coding, but it will not
be
much good unless you can be sure that document.MyForm.txtStep1.value
returns
the value of a checked button - and of course it is quite possible to
present  a set of radio buttons with nothing checked.

typeof() may help things along a fraction since it may be used (one
hopes!!)
to find "undefined" as in

if ( typeof(document.MyForm.txtStep1.value) =="undefined") ....

hth

Rodney

 BTW I use this function to get values from rb sets

function getRadioVal(rb){
var L=rb.length;var ret="";
for (var i = 0 ; i< L ; i++)
 { if(rb[i].checked) { ret=rb[i].value; break; } }
return(ret);
}

This returns an empty string if nothing is checked

gregory.john.toland at census.gov wrote:

> I have the following code:
>
> <form enctype="text/plain" id="myForm" method="get"
>       name="myForm" onSubmit="return true;">
>    <input checked id="txtStep1" name="txtStep1"
>           tabindex="1"
>           title="Tabular Profile" type="radio"
>           value="Tabular">Tabular</input>
>    <input id="txtStep1" name="txtStep1"
>           title="Narrative Profile" type="radio"
>           value="Narrative">Narrative</input>
> </form>
>
> In Netscape 4.X and IE 5.X the code:
>
>    alert( document.MyForm.txtStep1[01].value );
>
> returns "Narrative"
>
> In Netscape 6.1 the same code gives an error message in the Javascript
> console:
>
>    "Error: document.myForm.txtStep1[1] has no properties."
>
> Did something change?
>
> In Netscape 6.1 if I use:
>
>    alert( document.MyForm.txtStep1.value );
>
> I get the correct answer, "Narrative".  I cannot use this code in IE 5.X
> and NN 4.X, however.  It gives a result of "undefined".  Must we have
> different code for the two sets of browsers for accessing such basic
> properties of form elements?  Is there any documentation out there that
> talks about this?  According to
> http://developer.netscape.com/docs/manuals/js/client/jsref/radio.htm the
> last example shows my code should work under JS 1.3/NN 6.1.  Any ideas?
>
> Gregory J Toland





More information about the Javascript mailing list