Title: Plugin/Widget Coding &#8211; document.getElementById doesn´t work
Last modified: August 22, 2016

---

# Plugin/Widget Coding – document.getElementById doesn´t work

 *  [kosackenzipfel](https://wordpress.org/support/users/kosackenzipfel/)
 * (@kosackenzipfel)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/pluginwidget-coding-documentgetelementbyid-doesnt-work/)
 * Hello!
 * I have a problem creating a **plugin/widget **for wordpress. In the part of the
   code where the **backend-form** is created “**document.getElementById**” doesn
   ´t work. I can read the fields of the form but I cannot change their value using
   JavaScript (Code below):
 *     ```
       echo "<script type='text/javascript'>";
       echo "function feld_aendern()";
       echo "{";
       echo " var alterwert = document.getElementById('tt11').value;";
       echo " alert(alterwert);";
       echo " var aenderung = document.getElementById('tt11');";
       echo " aenderung.value = 'Neuer Wert';";
       echo " alert('...wieder nicht geklappt?');";
       echo "}";
       echo "</script>";
       echo "<p><input type='text' id='tt11' value='Alter Wert' onchange='feld_aendern()' /></p>";
       ```
   
 * The fields are generated by the .php – so why can I only read them (the ‘alert’
   works), but not change their values? Must be something stupid I don´t see…
    I
   also tried it excluding the JavaScript – with the same result…
 *     ```
       // hier endet PHP ?>
       <script type="text/javascript">
           function feld_aendern() {
               var alterwert = document.getElementById('tt11').value;
               alert(alterwert);
               var aenderung = document.getElementById('tt11');
               aenderung.value = 'Neuer Wert';
               alert('check?');
           }
       </script>
       <p><input type="text" id="tt11" value="Alter Wert" onchange="feld_aendern()"></p>
       <?php // hier gehts weiter mit PHP
       ```
   
 * I would be very glad if I anyone could help me!!!

The topic ‘Plugin/Widget Coding – document.getElementById doesn´t work’ is closed
to new replies.

## Tags

 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 0 replies
 * 1 participant
 * Last reply from: [kosackenzipfel](https://wordpress.org/support/users/kosackenzipfel/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/pluginwidget-coding-documentgetelementbyid-doesnt-work/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
