I am experiencing some unusual results with my jQuery and was hoping that somebody could enlighten me as to why. I am sure that jQuery is powerful enough to do this, so I wonder what I am doing wrong. Here is what I have (some seemingly simple and easy to understand code):
///////////reset default search entries/////////////
$("#sOrderByDLM").attr('checked', 'checked');
$("#sOrderByID").attr('checked', '');
$("#sOrderByPOIName").attr('checked', '');
$("#sOrderByAge").attr('checked', '');
$("#sOrderByOfficer").attr('checked', '');
$("#sOrderByDesc").attr('checked', 'checked');
$("#sOrderByAsc").attr('checked', '');
I have this inside a simple javaScript function that is called on the click of a non-submit type (normal) button. The problem is that when I click this, instead of it filling the sOrderByDLM
radio button, it actually fills the sOrderByOfficer
button and likewise with the bottom two jQuery statements (e.g., sOrderByAsc
becomes 'checked
' instead of sOrderByDesc
) Am I not blatantly telling jQuery to reset the 'checked
' attribute to that of the second argument, which is blank, except in the cases where I specifically set it to 'checked
' for the fields I intend to be default?
I experienced a similar problem with checkboxes, but I found a work around by simply calling the same statements in reverse order, but that doesn't seem to work here, though. If I set 'checked="checked"
' in razor everything is fine, but I need this button to work on the client side.
Anyway, if the HTML is necessary, I will provide it, but I doubt it is needed since the I have triple checked the ids to be sure.
Thanks for any help!
(And God Bless Stack Overflow, I don't know what I would do without you! :D)
UPDATE:
<tr>
<td class="orderlineupColor"><label for="sOrderByDLM">Date Last Modified</label><br/><input type="radio" id="sOrderByDLM" name="sOrderBy" style="margin-left: 115px;" value="OrderByDLM" @OrderByFiller[0] /></td>
<td class="orderlineupColor"><label for="sOrderByID">Entry ID</label><br/><input type="radio" id="sOrderByID" name="sOrderBy" style="margin-left: 115px;" value="OrderByID" @OrderByFiller[1] /></td>
<td class="orderlineupColor"><label for="sOrderByPOIName">POI Name</label><br/><input type="radio" id="sOrderByPOIName" name="sOrderBy" style="margin-left: 115px;" value="OrderByPOIName" @OrderByFiller[2] /></td>
<td class="orderlineupColor"><label for="sOrderByAge">Age</label><br/><input type="radio" id="sOrderByAge" name="sOrderBy" style="margin-left: 115px;" value="OrderByAge" @OrderByFiller[3] /></td>
<td class="orderlineupColor"><label for="sOrderByOfficer">Officer</label><br/><input type="radio" id="sOrderByOfficer" name="sOrderBy" style="margin-left: 115px;" value="OrderByOfficer" @OrderByFiller[4] /></td>
</tr>
<tr>
<td class="orderlineupColor2">In Descending Or<br/>Ascending Order:</td>
<td class="orderlineupColor2"><label for="sOrderByDesc">Descending Order</label><br/><input type="radio" id="sOrderByDesc" name="sAscOrDesc" style="margin-left: 115px;" value="OrderByDesc" @OrderByAscOrDescFiller[0] /></td>
<td class="orderlineupColor2"><label for="sOrderByAsc">Ascending Order</label><br/><input type="radio" id="sOrderByAsc" name="sAscOrDesc" style="margin-left: 115px;" value="OrderByAsc" @OrderByAscOrDescFiller[1] /></td>
<td class="orderlineupColor2"><button type="button" class="smallbtn" onclick="clearSortEntries()">Reset Sort Entries</button></td>
<td class="orderlineupColor2"></td>
</tr>