andrew4582

Create Select Option

Sep 27th, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Creates an option html element. example: alert(createOption("THIS IS TEXT","THIS IS VALUE"));*/
  2.     function createOption(text,value)
  3.     {
  4.         const optionfmt = "<option>[TEXT]</option>";
  5.         const optionvalfmt = "<option value='[VALUE]'>[TEXT]</option>";
  6.        
  7.         var formatted = "";    
  8.         if(value == null)
  9.             formatted = optionfmt.replace("[TEXT]", text);
  10.         else
  11.             formatted = optionvalfmt.replace("[TEXT]", text).replace("[VALUE]",value);
  12.        
  13.         return formatted;
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment