Weird span/radio button/JavaScript behavior...

M

madforplaid

Can anyone help me to figure out a strange span/radio button/JavaScript
behavior?

When clicking on the radio button for WEEK 2 below all works okay, but
when clicking on the label for the same week, button 41 gets selected
instead:

<td align="center">
<span title="WEEK 2"><label
onMouseOver="this.className='option_wk_even'; window.status='WEEK 2
'+calNowYear+' Schedule';" onMouseOut="this.className='option_off';
window.status='';"><input type="radio" name="buttons" value="33"
onClick="displaySchedule(this);">
<label style="cursor: hand;"
onClick="document.forms['training'].elements['buttons'][33].click();"><b>WEEK
2</b></label></label></span></td>

Any thoughts as to why this happens?

Thanks,

Paul
 
J

John Fereira

(e-mail address removed) wrote in
<span title="WEEK 2"><label
onMouseOver="this.className='option_wk_even'; window.status='WEEK 2
'+calNowYear+' Schedule';" onMouseOut="this.className='option_off';
window.status='';"><input type="radio" name="buttons" value="33"
onClick="displaySchedule(this);">
<label style="cursor: hand;"
onClick="document.forms['training'].elements['buttons'][33].click();"
^^^^^^^^^^^^^^^^^^^^^^^

I have to wonder about how you're referencing the radio element (and why
there is only one radio element). According to one site looked at:

All Radio objects are stored in the elements array of the corresponding
form. You can access a Radio object by indexing this array - either by
number (0 represents the first element in a form) or by using the value of
the name attribute.

My guess is that it's treating the 33 as an index into the array and not as
the value of the radio element. Try putting quotes around it or give each
radio object an id and reference it by id.
 
M

Michael Winter

On 03/09/2005 10:04, (e-mail address removed) wrote:

[snip]
When clicking on the radio button for WEEK 2 below all works okay, but
when clicking on the label for the same week, button 41 gets selected
instead:
[snip]

</label></label>

[snip]

Fix your markup; LABEL elements cannot be nested.

Mike
 
M

madforplaid

John,

Thanks for the reply.

You got me thinking - all of the elements of the array had been sorted
differently, but they were displayed consecutively. After I renumbered
the array elements based upon their order within the HTML, all is fine
now!!

I had 51 radio buttons in a table:

radio value 1 radio value 26
radio value 2 radio value 27
radio value 3 radio value 28

& so on, but each of the <tr><td> code order was causing the confusion.
Doing the following fixed it:

radio value 1 radio value 2
radio value 3 radio value 4
radio value 5 radio value 6

Thanks again.

Paul
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top