Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- calling a javascript function from a ROR controller ruby
- enter function nbFct() {
- var clipLists = ["Default", "Recent", "Sticky lists"];
- var option1 = ["a", "b"];
- var option2 = ["a", "x", "c"];
- var option3 = ["f", "e", "c", "d"];
- var listType = [];
- var optionType = [];
- for (var i = 0; i < clipLists.length; i++) {
- // create dynamic optgroup from clipLists
- listType[i] = document.createElement("optgroup");
- listType[i].label = clipLists[i];
- // alert(listType[i].label) ;
- if(listType[i].label == "Default"){
- for (var j = 0; j < option3.length; j++) {
- // create options and attach to optgroups
- optionType[j] = document.createElement("option");
- optionType[j].value = option3[j];
- // alert(optionType[j].value) ;
- optionType[j].appendChild(document.createTextNode(option3[j]));
- listType[i].appendChild(optionType[j]);
- }
- }
- else if(listType[i].label == "Recent"){
- for (var j = 0; j < option2.length; j++) {
- // create options and attach to optgroups
- optionType[j] = document.createElement("option");
- optionType[j].value = option2[j];
- // alert(optionType[j].value) ;
- optionType[j].appendChild(document.createTextNode(option2[j]));
- listType[i].appendChild(optionType[j]);
- }
- }
- else{
- for (var j = 0; j < option1.length; j++) {
- // create options and attach to optgroups
- optionType[j] = document.createElement("option");
- optionType[j].value = option1[j];
- // alert(optionType[j].value) ;
- optionType[j].appendChild(document.createTextNode(option1[j]));
- listType[i].appendChild(optionType[j]);
- }
- }
- }
- // set the default
- optionType[1].selected = true;
- // clear select menu and append optgroups
- var selectMenu = document.getElementById("clipListOption");
- while (selectMenu.hasChildNodes()) {
- selectMenu.removeChild(selectMenu.firstChild);
- }
- for (var i = 0; i < clipLists.length; i++) {
- if (listType[i].hasChildNodes()) { selectMenu.appendChild(listType[i]); }
- }
- }
Add Comment
Please, Sign In to add comment