Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- jQuery plug-in to create select options without to create manually html every time
- * Copyright (c) 2013 Andrew Hodgson
- //Example:
- jQuery(function($){
- //create option's html
- var optionHtml= $.Options.create("New York","NY");
- $("#stateselect").append(optionHtml);
- //add select's option directly
- $("#stateselect")
- .addOption("Texas","TX")
- .addOption("Maine","MA");
- //add number options
- for(var i = 1;i<= 10;i++)
- $("#inputCntSel").addOption(i);
- });
- */
- (function($) {
- $.Options = {
- create: function(text,value){
- const optionfmt = "<option>[TEXT]</option>";
- const optionvalfmt = "<option value='[VALUE]'>[TEXT]</option>";
- var formatted = "";
- if(value == null)
- formatted = optionfmt.replace("[TEXT]", text);
- else
- formatted = optionvalfmt.replace("[TEXT]", text).replace("[VALUE]",value);
- return formatted;
- }
- };
- $.fn.addOption = function(text,value) {
- var select=$(this);
- var optionHtml= $.Options.create(text,value);
- return select.append(optionHtml);
- };
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment