Suggestions for html tag info required for jQuery Plugin
- by Toby Allen
I have written a tiny bit of jQuery which simply selects all the Select form elements on the page and sets the selected property to the correct value. Previously I had to write code to generate the Select in php and specify the Selected attribute for the option that was selected or do loads of if statements in my php page or smarty template.
Obviosly the information about what option is selected still needs to be specified somewhere in the page so the jQuery code can select it.
I decided to create a new attribute on the Select item
<Select name="MySelect" SelectedOption="2"> <-- Custom Attr SelectedOption
<option value="1">My Option 1 </option>
<option value="2">My Option 2 </option> <-- this option will be selected when jquery code runs
<option value="3">My Option 3 </option>
<option value="4">My Option 4 </option>
</Select>
Does anyone see a problem with using a custom attribute to do this, is there a more accepted way, or a better jquery way?