PDA

View Full Version : Confirm Button Click Alert PROBLEM


nibs
02-03-2003, 06:19 PM
Hi,

I am using the following HTML form and would like for the user to be warned that the Delete (Submit) button will permanently delete the file when they click submit.

The JS I am trying to obtain should offer the user an Ok or Cancel option. Cancel should do nothing and ok should just continue with the allocated task.

I have been trying to use this code below (Aside : Will the fact that I am using PHP affect the JavaScript).

As you can see the ELSE option in the head part of the code simply goes back a page BUT i don't want that I just want no action taken. If they click yes to continue as normal i.e. execute delete.php (Name of the file).

Thank you in advance,

Nibs


************ HEAD ****************
<SCRIPT LANGUAGE="JavaScript">
function drawAlert()
{
var answer=confirm(" Permanently Delete Job Description")
if (answer) {
document.write("");
}
else {
history.go(-1);
}
</script>
************ BODY ******************

<form name="viewJobs" action=" <? echo ($_SERVER['PHP_SELF']); ?> " method="post">
<input type="hidden" name="formSubmitted" value="1"/>
To delete a job description from the DGI Datbase :
<ol class="delAdmin">
<li>Type the Job Id of the job description you want to delete.</li>
<li>Ensure the "Delete Job Description" button is clicked.</li>
<li>Click the "Locate" button to locate the job description to be deleted.</li>
</ol><br><br>
<input align="center" name="searchTerm" type="text">
<input type="submit" value="Delete" class="submit" onClick="drawAlert()" >

cg9com
02-03-2003, 06:21 PM
PHP wont affect your javascript, unless you want it to that is :)
you could just try

else {
return false;
}

nibs
02-03-2003, 06:43 PM
Hi cg9com,

Just tried that but I think the problem may be in the fact that there is a clash in the


<input type="submit" value="Delete" class="submit" onClick="drawAlert()" >



maybe type should equal button for it to work - when I press the delete button . It does not even read the JS at all. It works fine but prompt script doesn't implement.

i.e. I dont think it calls drawAlert()


Thank you for your fast response. I look forward to finding the problem,

Nibs

arnyinc
02-03-2003, 07:33 PM
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function drawAlert(){
var answer=confirm(" Permanently Delete Job Description")
if (!answer)
return false;
}
</script>
</head>

<body>
<form name="viewJobs" action="sub.htm " method="post" onSubmit="return drawAlert();">
<input type="hidden" name="formSubmitted" value="1"/>
To delete a job description from the DGI Datbase :
<ol class="delAdmin">
<li>Type the Job Id of the job description you want to delete.</li>
<li>Ensure the "Delete Job Description" button is clicked.</li>
<li>Click the "Locate" button to locate the job description to be deleted.</li>
</ol><br><br>
<input align="center" name="searchTerm" type="text">
<input type="submit" value="Delete" class="submit">
</body>
</html>


edit: I changed it from an onclick for the submit bitton to an onsubmit for the form. That way you only have to return false if they click cancel.

nibs
02-03-2003, 09:13 PM
Thank you arnyinc.

It works exactly as I hoping. Thank you for taking the time to reply. Do you know of any exceptional beginner javascript web sites.


Once again thank you,

Nibs

cg9com
02-03-2003, 09:23 PM
you could try W3Schools (http://www.w3schools.com)
or just do some searches