 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 20th, 2004, 06:29 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Javascript alert box
Hi there
I have this function set up:
function ConfirmDelete(varURL)
{
if (confirm("Are you sure you want to delete this Listing?"))
window.open(varURL, "_top");
}
then further down the page, I need to call the function but I think I've got something wrong but not sure what; here's where I call the function:
<form name="frm_del" method="post" action="onClick=javascript:ConfirmDelete ('delete.asp?ListingsID=<%=rsListings("ListingsID" )%>');">
I think it's something to do with the syntax.
Any help greatly appreciated.
thanks
Adam
|
|

February 20th, 2004, 06:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I do not know to much about this stuff, but I think you should use the onSubmit event, and not the action attribute. As it is you have got an event in the action attribute, and that will not work.
Hope it helps
Jacob.
|
|

February 20th, 2004, 06:56 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry! A correction to the above... It is not an event, it is rather an attribute, so you can do something like this...
<FORM ONSUBMIT="alert('something');">
I think ;)
Jacob.
|
|

February 20th, 2004, 07:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Do you want to submit the form if user chooses yes or do you wish to open a secondary window or both. If both then change the function to the following and include it in the onsubmit event handler:
Code:
function ConfirmDelete(varURL)
{
if (confirm("Are you sure you want to delete this Listing?"))
{
window.open(varURL, "_top");
return true;
}
return false;
}
This will prevent submission if they chosse 'Cancel' but your form tag needs modifying. Haow depends on your intensions. If you want the new window to appear with the forms results displayed in it that requires use of the target attribute.
--
Joe
|
|

February 20th, 2004, 07:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great, thanks for your input guys; got there in the end!
|
|

March 3rd, 2004, 12:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Further to this, I'm getting an error message, 'Page cannot be displayed'.
The reason for this is because after posting the form (after the alert etc), the path that the browser is looking for is
secure/PostagePacking/undefined
I don't know why it's returning undefined but here's my coding:
<script language="javascript" type="text/javascript">
function ConfirmBasePrice(varURL)
{
if (confirm("Make sure you haven't changed\nthe base level from £1.00!"))
{
window.open(varURL, "_top");
return true;
}
return false;
}
</script>
and further down:
<form name="form1" method="post" onSubmit="return ConfirmBasePrice();" action="process_update.asp?id=<%=rsPacking("PPid") %>">
Any help much appreciated.
Adam
|
|

March 3rd, 2004, 12:38 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Can you describe in stages what exactly you want to happen? For instance if they click 'OK' do you want the form to submit and the window to open, or do you want to open the result of the post to the popup window?
--
Joe
|
|

March 3rd, 2004, 01:06 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe
Yes, if the user clicks OK on the alert box, then I want the form to submit and the window to open, otherwise, if the user clicks cancel, then I want the page to stay as it is.
As it stands, although I get the error as I described before, the changes that I request from the post are still committed to the database.
thanks
Adam
|
|

March 3rd, 2004, 01:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
But asking for the new window to open as "_top" meansyou want to replace the cureent frameset, don't you want a popup window?
--
Joe
|
|

March 3rd, 2004, 01:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Joe
No I want to replace the current frameset with the same page but with the new values on it.
thanks
Adam
|
|
 |