I want to INSERT VALUES but I don't want user to navigate to this page
Question by user1304328
I want to INSERT VALUES after user has clicked OK on the confirmation box. Now the confirmation box works well. The only problem I can see is that when the user clicks ‘OK’ I want the INSERT VALUES to happen on a seperate page (insertQuestion.php) but I do not want the form to be navigated to that page. I want the form to navigate the way it is doing which is either submit to its own page or submit to create_session.php depending on the situation ($action).
So how can I INSERT VALUES into the database without navigating the user to that page (insertquestion.php) after the user has clicked ‘OK’ in the confirmation box?
below is the javascript code where the confirmation box appears and if confirmation is ‘OK’, it submits the form:
function showConfirm(){
var confirmMsg=confirm("Do you want to Proceed" + "n" );
if (confirmMsg==true)
{
submitform();
}
}
function submitform()
{
var QandAO = document.getElementById("QandA");
QandAO.submit();
}
Answer by Starx
Post the form using an ajax request.
A simple example using jQuery
$("#yourbutton").click(function() {
var fieldvalue = $("#inputname").val(); //grab the form value
$.post("yourpage.php", //send it to yourpage.php
{
field1: fieldvalue
}, function(data) {
//do something on success
}
);
});