Javascript help

Author
Discussion

KITT

Original Poster:

5,339 posts

242 months

Thursday 17th March 2005
quotequote all
I'm trying (and failing!) to get the confirm function working under anything other than IE. My code is as follows:
I wrote said:
< script language="Javascript">
function AreYouSure() {
if (confirm("Do you really want to do this?"))
DeleteForm.submit();
else
return false;
}
< /script>

< form action="deletestuff.php" method="post" name="DeleteForm">
.
.
.
.
.
.
< table border="0">
< tr>
< td width="4" background="but4.gif">< /td>
< td background="but5.gif" class="PicButton" onclick="AreYouSure();">< font color="#222222">Delete selected< /font>
< /td>
< td width="4" background="but6.gif">< /td>
< /tr>
< /table>
< /form>
I've had to put a space infront of all the html tags as PH seems to strip them off

This works fine under IE but the form won't sumbit under Netscape or Firefox.

Any suggestions?

Mark.S

473 posts

278 months

Thursday 17th March 2005
quotequote all
try onclick="javascript:AreYouSure();"

KITT

Original Poster:

5,339 posts

242 months

Thursday 17th March 2005
quotequote all
Cheers Mark but I think I should have added that the dialog asking you to "ok" or "cancel" the request does appear in Netscape, but when you click "ok" nothing happens (i.e. the form does not get submitted). Any more ideas folks

LaurenceFrost

691 posts

253 months

Thursday 17th March 2005
quotequote all
Rather than having the javascript submit the form, why not instead have it redirect to the page with a URL paramater ($_GET in php) set, which would be the confirmation to delete.

For example:
DeleteDtuff.php would pop up the message when called.

Clicking yes would redirect to:
deleteStuff.php?confirm=1

PHP will then know it's ok to delete.

GreenV8S

30,227 posts

285 months

Thursday 17th March 2005
quotequote all
Stick an alert before and after the submit to make sure it is running the code you think it is.

You function returns false in one case and nothing in the other, they can't both be right? I don't see any need for it to return anything.

As a matter of principle, put curly braces round every if/else clause to avoid control logic flaws when you add debug statements.

It may be that the reference to DeleteForm is not resolving correctly so you are getting a null. You could check for this explicitly. I tend to look elements up by ID, it isn't always necessary but I've got into the habbit because the name references don't always work.

robbieduncan

1,981 posts

237 months

Thursday 17th March 2005
quotequote all
Could be a scope problem. try document.DeleteForm.submit()

KITT

Original Poster:

5,339 posts

242 months

Thursday 17th March 2005
quotequote all
robbieduncan said:
Could be a scope problem. try document.DeleteForm.submit()
Excellent! That's what the problem was! Many thanks