Suggestions for html tag info required for jQuery Plugin

Posted by Toby Allen on Programmers See other posts from Programmers or by Toby Allen
Published on 2012-11-11T19:29:36Z Indexed on 2012/11/11 23:12 UTC
Read the original article Hit count: 476

Filed under:
|
|

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?

© Programmers or respective owner

Related posts about JavaScript

Related posts about html