TransWikia.com

How to use value from modal tinymce windowManager?

WordPress Development Asked by Patrick Paul on December 10, 2020

Hello im using a Javascript File for integrating a button with a function in my TinyMCE editor in my WordPress enviroment. I want to get the value from the select-Tag field and use it for further operations. How i can get the value which is selected?

init : function(ed, url)
        {
            ed.addButton('code-hightlight',
            {
              title : 'Code-Highlight',
              cmd : 'code-hightlight-cmd',
              image : url + '/prism-icon.jpg'
            });
            ed.addCommand('code-hightlight-cmd', function()
            {
              tinymce.activeEditor.windowManager.open
              ({
                  title: 'Code-Highlighter',
                  width : 300,
                  height : 300,
                  html :
                      '<label>Programmiersprache:<select id="programming-language-id" name="programming-language-name" size="1"><option>ABAP</option><option>C#</option><option>CSS</option><option>HTML</option><option>Java</option><option>Javascript</option><option>PHP</option><option>SQL</option></select></label>',
                  buttons: [
                      {
                          text: 'Bestätigen',
                          onclick: function()
                          {
                              var id_id = tinymce.get('programming-language-id');
                              alert(id_id);
                              var id_name = tinymce.get('programming-language-name');
                              alert(id_name);
                              tinymce.activeEditor.execCommand('mceInsertContent', false, "some text");
                              tinymce.activeEditor.windowManager.close();
                          }
                      },
                      {
                          text: 'Schließen',
                          onclick: 'close'
                      }
                  ]
              });
            });
        },

enter image description here

One Answer

If I read your question correctly, this is more related to Javascript programming than WordPress.

To get the selected option value or text of a HTML select tag, use:

var e = document.getElementById("programming-language-id");
var value = e.options[e.selectedIndex].value;  //your code doesn't set option value
var text = e.options[e.selectedIndex].text;  //this will get the selected option text

Answered by hcheung on December 10, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP