Reputation: 33
I'm currently programming a website system as part of my studies. I'm using PHP,HTML and Javascript throughout the project. I'm a novice programmer and i'm learning as i go along.
My current problem is that when a form submit button is pressed e.g. UPDATE or DELETE. I wanted a confirmation box asking the user 'Are you sure you want to submit?' using javascript. However whenever I click the button , an empty alert box appears even though there is text inside the JS function. Please look at the code below ! :
function confirm()
{
return alert("Are you want to submit the form"?);
}
</script>
The html code is echoed in a php while loop
echo "<td>" . "<input type=submit name=update value=update onclick='confirm();'" . "> </td>";
echo "<td>" . "<input type=submit name=delete value=delete onclick='confirm();'" . "> </td>";
I am grateful for anyone taking their time to help !
Upvotes: 1
Views: 1893
Reputation: 33
Problem solved guys! appreciate all your help, was an error in with the ? in the javascript function. Funnily enough, it wasn't using confirm as my function name! won't use confirm next time for good practice.
return alert("Are you want to submit the form"?); <- ? outside of ""
Corrected
return alert("Are you want to submit the form?");
Upvotes: 1
Reputation: 8276
confirm()
is already a Javascript function. The question mark should also remain inside the double-quotes. Change your function name for clarity:
function confirmForm()
{
return alert("Are you want to submit the form?");
}
echo "<td>" . "<input type=submit name=update value=update onclick='confirmForm();'" . "> </td>";
Upvotes: 0
Reputation: 38
if(confirm("question")){
// yes
} else {
//no
}
confirm() is a javascript reserved word
Upvotes: 0