The squad.asp page of Battrick has a select element which can be used to sort the order of the squad. This investigation looks at how the use of this element can be improved.
To avoid any possible insight into the variables used within Battrick, some of the ASP code has been removed.
Contents of this page
Current code
<FORM NAME='SOrder' Method='POST' action='natsquad.asp?userID=<%=sortTeamID%>'><SELECT NAME='OrderBy' onchange="document.SOrder.submit()"><%If … Then%><OPTION VALUE=6<%if … Then response.write " SELECTED"%>>Shirt No</OPTION><%End If%><OPTION VALUE=1<%if … Then response.write " SELECTED"%>>First name</OPTION><OPTION VALUE=2<%if … Then response.write " SELECTED"%>>Last name</OPTION><OPTION VALUE=3<%if … Then response.write " SELECTED"%>>Player ID</OPTION><OPTION VALUE=4<%if … Then response.write " SELECTED"%>>Age</OPTION><OPTION VALUE=5<%if … Then response.write " SELECTED"%>>Battrick Rating</OPTION><%If … Then%><OPTION VALUE="">---------------</OPTION><OPTION VALUE=7<%if … Then response.write " SELECTED"%>>Batting</OPTION><OPTION VALUE=8<%if … Then response.write " SELECTED"%>>Bowling</OPTION><OPTION VALUE=9<%if … Then response.write " SELECTED"%>>Wicket Keeping</OPTION><<OPTION VALUE=10<%if … Then response.write " SELECTED"%>>Fielding</OPTION><OPTION VALUE=11<%if … Then response.write " SELECTED"%>>Stamina</OPTION><%If … Then%><OPTION VALUE=13<%if … Then response.write " SELECTED"%>>Fitness Level</OPTION><%Else%><OPTION VALUE=12<%if … Then response.write " SELECTED"%>>Fitness Level</OPTION><%End IfEnd If%></SELECT></FORM>
Improvement 1 - Code
- Convert HTML to lowercase
- Convert boolean attribute to attribute="value" for XHTML
- Quotify Value attribute value.
<form name="SOrder" method="POST" action="natsquad.asp?userID=<%=sortTeamID%>"><select name="OrderBy" onchange="document.SOrder.submit()"><%If … Then%><option value="6"<%if … Then response.write " selected=""selected"""%>>Shirt No</option><%End If%><option value="1"<%if … Then response.write " selected=""selected"""%>>First name</option><option value="2"<%if … Then response.write " selected=""selected"""%>>Last name</option><option value="3"<%if … Then response.write " selected=""selected"""%>>Player ID</option><option value="4"<%if … Then response.write " selected=""selected"""%>>Age</option><option value="5"<%if … Then response.write " selected=""selected"""%>>Battrick Rating</option><%If … Then%><option value="">---------------</option><option value="7"<%if … Then response.write " selected=""selected"""%>>Batting</option><option value="8"<%if … Then response.write " selected=""selected"""%>>Bowling</option><option value="9"<%if … Then response.write " selected=""selected"""%>>Wicket Keeping</option><option value="10"<%if … Then response.write " selected=""selected"""%>>Fielding</option><option value="11"<%if … Then response.write " selected=""selected"""%>>Stamina</option><%If … Then%><option value="13"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%Else%><option value="12"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%End IfEnd If%></select></form>
Improvement 2 - Visual
- Use optgroup element for member only options
<form name="SOrder" method="POST" action="natsquad.asp?userID=<%=sortTeamID%>"><select name="OrderBy" onchange="document.SOrder.submit()"><%If … Then%><option value="6"<%if … Then response.write " selected=""selected"""%>>Shirt No</option><%End If%><option value="1"<%if … Then response.write " selected=""selected"""%>>First name</option><option value="2"<%if … Then response.write " selected=""selected"""%>>Last name</option><option value="3"<%if … Then response.write " selected=""selected"""%>>Player ID</option><option value="4"<%if … Then response.write " selected=""selected"""%>>Age</option><option value="5"<%if … Then response.write " selected=""selected"""%>>Battrick Rating</option><%If … Then%><optgroup label="---- Skill ----"><option value="7"<%if … Then response.write " selected=""selected"""%>>Batting</option><option value="8"<%if … Then response.write " selected=""selected"""%>>Bowling</option><option value="9"<%if … Then response.write " selected=""selected"""%>>Wicket Keeping</option><option value="10"<%if … Then response.write " selected=""selected"""%>>Fielding</option><option value="11"<%if … Then response.write " selected=""selected"""%>>Stamina</option><%If … Then%><option value="13"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%Else%><option value="12"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%End If</optgroup>End If%></select></form>
optgroup option {padding-left: 0;}
Improvement 3 - JavaScript
Cameron explains the problem better than I can. He also provides the solution.
- Changed form name attribute to form id.
- Added select id attribute.
- Removed select onchange attribute
- Page links to select_onchange.js
<form id="SOrder" method="POST" action="natsquad.asp?userID=<%=…%>"><select id="OrderBy" name="OrderBy"onchange="document.SOrder.submit()"><%If … Then%><option value="6"<%if … Then response.write " selected=""selected"""%>>Shirt No</option><%End If%><option value="1"<%if … Then response.write " selected=""selected"""%>>First name</option><option value="2"<%if … Then response.write " selected=""selected"""%>>Last name</option><option value="3"<%if … Then response.write " selected=""selected"""%>>Player ID</option><option value="4"<%if … Then response.write " selected=""selected"""%>>Age</option><option value="5"<%if … Then response.write " selected=""selected"""%>>Battrick Rating</option><%If … Then%><optgroup label="---- Skill ----"><option value="7"<%if … Then response.write " selected=""selected"""%>>Batting</option><option value="8"<%if … Then response.write " selected=""selected"""%>>Bowling</option><option value="9"<%if … Then response.write " selected=""selected"""%>>Wicket Keeping</option><option value="10"<%if … Then response.write " selected=""selected"""%>>Fielding</option><option value="11"<%if … Then response.write " selected=""selected"""%>>Stamina</option><%If … Then%><option value="13"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%Else%><option value="12"<%if … Then response.write " selected=""selected"""%>>Fitness Level</option><%End If</optgroup>End If%></select></form>