Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 53 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. calling a javascript function from a ROR controller ruby
  2. enter function nbFct() {
  3. var clipLists = ["Default", "Recent", "Sticky lists"];
  4. var option1 = ["a", "b"];
  5. var option2 = ["a", "x", "c"];
  6. var option3 = ["f", "e", "c", "d"];
  7. var listType = [];
  8. var optionType = [];
  9. for (var i = 0; i < clipLists.length; i++) {
  10. // create dynamic optgroup from clipLists
  11. listType[i] = document.createElement("optgroup");
  12. listType[i].label = clipLists[i];  
  13. //  alert(listType[i].label) ;
  14. if(listType[i].label ==  "Default"){
  15.     for (var j = 0; j < option3.length; j++) {
  16. // create options and attach to optgroups
  17.     optionType[j] = document.createElement("option");
  18.     optionType[j].value = option3[j];
  19. //      alert(optionType[j].value) ;
  20.     optionType[j].appendChild(document.createTextNode(option3[j]));
  21.     listType[i].appendChild(optionType[j]);
  22.     }
  23. }
  24. else if(listType[i].label ==  "Recent"){
  25.     for (var j = 0; j < option2.length; j++) {
  26. // create options and attach to optgroups
  27.     optionType[j] = document.createElement("option");
  28.     optionType[j].value = option2[j];
  29. //      alert(optionType[j].value) ;
  30.     optionType[j].appendChild(document.createTextNode(option2[j]));
  31.     listType[i].appendChild(optionType[j]);
  32.     }
  33.    }
  34.    else{
  35.       for (var j = 0; j < option1.length; j++) {
  36.   // create options and attach to optgroups
  37.         optionType[j] = document.createElement("option");
  38.         optionType[j].value = option1[j];
  39.   //            alert(optionType[j].value) ;
  40.         optionType[j].appendChild(document.createTextNode(option1[j]));
  41.         listType[i].appendChild(optionType[j]);
  42.       }
  43.     }
  44.   }
  45.  // set the default
  46.  optionType[1].selected = true;
  47.  // clear select menu and append optgroups
  48.  var selectMenu = document.getElementById("clipListOption");
  49. while (selectMenu.hasChildNodes()) {
  50. selectMenu.removeChild(selectMenu.firstChild);
  51. }
  52.  for (var i = 0; i < clipLists.length; i++) {
  53.     if (listType[i].hasChildNodes()) { selectMenu.appendChild(listType[i]); }
  54.   }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top