Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio button checked attribute doesn't work

Status
Not open for further replies.

mdwyer

Programmer
Oct 9, 2003
389
US
I have this weird problem where a radio button with the 'checked' attribute does not show the button checked. Here's the code:

<td><input name=x type=radio value=0 checked>N
<input name=x type=radio value=1 >C
</td>

The output is:
( )N ( )C

when it should be:
(@)N ( )C

(loosely rendered :)


I included the <td> tags in case embedding the use of a table sheds some light. Also, the document is being processed by an ASP clone, called CSP, from Crystal Decisions.

Any ideas would be appreciated.
 
Your attribute values should be in quotes, though I don't know if this is the cause of your problem or not. I tested this code in IE 6 and Mozilla and the 'N' radio button was checked.

 

The code should work fine as-is.

Do you know if the ASP clone is doing any processing on your code? Can you view the final source and see if it differs at all?

Dan
 
As Dan mentions, it should work... and seems to work fine on IE6.

Netscape 4.x won't display the checkboxes if there isn't opening/closing <FORM> tags, but you seem to indicate that there is a problem with functionality rather than display.

Is the source file available to view on the web?

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Thanks for the help. I've tried single and double quotes around the attribute values, checked=&quot;checked&quot;, true, 0, etc. I orignally failed to add the enclosing <form></form> tags, but resolved that too. Still no &quot;dot&quot; in the middle of the &quot;checked&quot; button. (The problem IS with display, not with functionality. I have not gotten to the point of writing code to read the values of the buttons. Actually, I don't think I've even tried clicking the buttons to see if a value will &quot;set.&quot;)

Monday I will strip down the code to the bare essentials and post it if it still fails.
 
Is that being processed by the dynamic code? I ran into a problem with asp one time something to the effect of
<input type = &quot;radio&quot; name = &quot;myRadio&quot; value = &quot;myValue&quot;<%if rs(&quot;field&quot;) = &quot;myValue&quot; then response.write(&quot;Checked&quot;)%>>

the out put would be
<input type = &quot;radio&quot; name = &quot;myRadio&quot; value = &quot;myValue&quot;Checked>
No space between the &quot; and the C. I added a space just before the asp code and it worked fine.

thereptilian120x120.gif
 
Thanks for the willingness to help. The information I did not include in my orignal post was the source of the problem: the code was included in a loop! Because the loop iterated many, many times, I did not see that the there was a checked radio button in the very last row of my table. It showed up when I converted the loop to javascript with only a few iterations. As soon as I added the loop index to the field names, the check came on where expected.

So the code actually looked more like this (in javascript):

for (i=1; i<3; i++ ) {
document.write( &quot;<tr>&quot; +
&quot;<td><input name=x type=radio value=0 checked>N
&quot; <input name=x type=radio value=1 >C
&quot;</td></tr>&quot; );
}

and the output was like this:

( )N ( )C
(@)N ( )C

My correction will look something like:

for (i=1; i<3; i++ ) {
document.write( &quot;<tr>&quot; +
&quot;<td><input name=x&quot;+i +&quot; type=radio value=0 checked>N
&quot; <input name=x&quot;+i +&quot; type=radio value=1 >C
&quot;</td></tr>&quot; );
}

for output like this:

(@)N ( )C
(@)N ( )C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top