Get real-time button value and send to postmeta database

How do I get button value and send to postmeta database?
When you click the button. Have to update the file of the plugin testok: WP-content/plugins/testok/file-update-button.php
It has a function in this directory of the plugin!
The code will go to a sidebar in the widget text code plugin that is in the description!
The selected value on or off has to be visible on all pages!

<button id="toggle" name="test1" onclick="myFunction20()" value="on">on</button>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>

function myFunction20() {
var change = document.getElementById("toggle");

var passValue  = change.value;
if (change.innerHTML == "on")
{
change.innerHTML = "off";
change.value= "off";
}
else {
change.innerHTML = "on";
change.value= "on";
}
<?php $plugins_url = plugins_url();?>
$.ajax({
type: 'POST',
  url: "<?=$plugins_url.'/testok/file-update-button.php';?>",
  cache: false,
  data: { 
        'passValue': passValue
    },
  success: function(html){
    
	alert(html)
	return false;
  }
});

alert(passValue);
}

</script>
<?php
function update_meta_key1() {
if ( isset( $_POST['test1'] ) ) {
update_post_meta( '20', 'your_meta_key1', $_POST['test1'] );
}}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.