• how do i get the code below to be selected on all pages and send the selected value to database

    <html>
    <body>

    <button id=”toggle” name=”test” onclick=”myFunction()”>on</button>

    <script>

    function myFunction() {
    var change = document.getElementById(“toggle”);
    if (change.innerHTML == “on”)
    {
    change.innerHTML = “off”;
    }
    else {
    change.innerHTML = “on”;
    }
    }

    </script>
    </body>
    </html>

    function update_your_meta_key( $post_id ) {
    if ( isset( $_POST[‘test’] ) ) {
    update_post_meta( $post_id, ‘your_meta_key’, $_POST[‘test’] );
    }
    and if it’s not too much to ask to update this plugin without reloading the page

    • This topic was modified 5 years, 7 months ago by manoodin.
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The HTML and JavaScript needs to be on a template somewhere. A template that loads on all pages like header.php or footer.php. If you want the toggle button elsewhere, there may be a action hook you could use that fires within the page content itself. Which action is theme dependent.

    To send a value to the server without reloading the page, you need to use Ajax techniques. For more on Ajax, please refer to the Plugin Handbook.

Viewing 1 replies (of 1 total)
  • The topic ‘Toggle Button add value all page’ is closed to new replies.