As mentioned in the comments use the below to make things better you would assign your value to id or any attribute you want to call it and for each button added you use the class attribute so that you can have multiple buttons added without any problems and also to avoid having many click event declarations. Ofcoarse you would have to include your jquery script tag as well
// echo "<input type = 'button' onclick = 'activateit(".json_encode($name).")' value = '$name'>"; is change to the below
echo "<input type = 'button' id=".json_encode($name)." value = '$name' class='added_button'>";
we then use $ (document).on
because we want the event to be fired for any buttons that exists and also if there are more buttons added after the page loads
$ (document).on ('click', '.added_button', function (e) {
// this will be added if you dont want a form to submit when the button is pressed if it is in a form
// or to stop it from doing whatever it was meant to do
e.preventDefault ();
var name = this.id; // this will give you the value 'chai'
// to test it we do an alert
alert (name);
// add your code here
});
to include jquery use <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>