When a user clicks on a button (in a form), a javascript prompt box will appear asking for the user's name, then I want to send that javascript promp data into php, so that I can send it to a phpmyadmin database. Note that I have tried using an xmlhttprequest, but that didnt work, because the website is in https and not http
Here is the html form:
<form method="post" id="user_form" action="Pages/Intro/Intro.php">
<input class="button" id ="start_button" type="button" name ="txt" onclick="loadUserName()" value="Go to Game(push Twice)">
<br>
<input class="button" id="help_button" name="help" type="button" onclick="location.href='Pages/Help/Help.html';" value="Help/F.A.Q" >
<br>
</form>
But, I am not sure how to send this form data
JS (not sending to https):
function sendTextToServer(txt) {
var xhr = new XMLHttpRequest();
var formData = new FormData(myForm);
xhr.open("POST", "https://foo.php"); //Server goes after Post Method
//formData.append("txt", txt);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.addEventListener("readystatechange", function() {
if (xhr.readyState == 4 && xhr.status == 200) { // state DONE, status OK
// your request has been received, do what you want with the result here.
}
});
xhr.send(formData);
}