Alternative to the getElementsByName() method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    Alternative to the getElementsByName() method

    I'm attempting to intercept the click event for RadioButons in an attempt to ask the user for confirmation of their action.

    I determined that Internet Explorer does not reset the previous selection if the user was to cancel the action.

    In order to reset the previous select (cancel the new selection) I have to save a reference to the original selected radio button....well actually right now I'm just attempting to save the ID of the original radio button.

    Anyways, my problem isn't entirely related to this.

    My problem is that I'm trying to intercept the click event for an ASP.NET RadioButtonList control.

    My server code provides the client ID of the RadioButtonList control so that my JavaScript control can apply itself to the associated controls.

    Apparently the ASP.NET RadioButtonList renders as an HTML Table element with rows of radio buttons:
    Code:
    <table id="RadioButtonList1" border="0">
    	<tr>
    		<td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_0">1</label></td>
    	</tr><tr>
    		<td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="2" checked="checked" /><label for="RadioButtonList1_1">2</label></td>
    	</tr><tr>
    		<td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="3" /><label for="RadioButtonList1_2">3</label></td>
    	</tr>
    </table>
    So instead of using the $get() method (the document.getEle mentByID method) I tried using the document.getEle mentsByName() method when I discover that the element doesn't have a type.

    The problem is that the getElementsByNa me method is only returning the Table and not the RadioButtons.

    Is there something else that I can use to retrieve the RadioButtons so that I don't have to loop through the table cells?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you could try
    Code:
    var tbl = … // the table
    var boxes = tbl.getElementsByTagName("input"); // provided there are only the checkboxes in the table

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I don't know what changed but after much fiddling with this the getElementsByNa me method decided to start working the way I though it it should (returning me all elements that have the name provided).

      I must be tired or something...

      Thanks Dormilich

      Comment

      Working...