[Javascript] Pop up in javascript

Chris T christ at saeweb.com
Wed Mar 10 13:24:20 CST 2004


The first thing I notice is your function name. I would get away from the
word "set".

To answer you first question, you use a confirm() modal dialogue box. It
will take the focus away from the site and halt processing of any script,
and allow you to check the user's response. As such:

===============
// watch for wrapping
function DeleteFunction(){// Change to your name
    var doDelete = confirm("Are you sure you want to delete. Click \"Ok\" to
delete it or \"Cancel\".")
    if(doDelete){
        // Send them wherever or perform whatever action because they
clicked Ok.
    }
}
===============


Now the 2nd part of your question is more about design. I personally
wouldn't update the form's action, but rather in the DeleteFunction, I'd put
a redirect to the page you want to send the user to. Similar to something
below.

===============
location.href = "/page/you/want/them/to/go/to/path.asp?id=" + objEl.value
===============

But using your method, on the line where I put "// Send them...", you should
do something like this:

===============
document.forms[0].dispatch.value = target
// of course assuming target was passed in,
// which wasn't in my function
===============

Chris Tifer
http://emailajoke.com


----- Original Message ----- 
From: Samyukta Akunuru
To: javascript at LaTech.edu
Sent: Wednesday, March 10, 2004 1:54 PM
Subject: [Javascript] Pop up in javascript


Hi

I want to show a pop up (delete confirmation in my page) when user clicks on
delete button.The pop up will show "Are you sure you want to delte-yes or
no"
If user clicks on yes, then my page should set a page variable names
"dispatch" to "delete".ANd then call my form's post action, which will route
it to the next page...
how do i accomplish these two tasks for the onlye one button click?
Thanks in advance,
Sam.

My code below:


<SCRIPT LANGUAGE="JavaScript">
function set(target) {document.forms[0].dispatch.value=target;}
</script>
<table border="1" width="100%">
<tr>
<th>
<html:submit onclick="set('delete');">Delete</html:submit>
......

so basically i want a pop up when user clicks the above Delete button
(struts uses <html:submit  to generate a HTML button) and when i click on
the yes on this pop up, i want the set(target) to get set
Thanks in advance for help,
Sam.




More information about the Javascript mailing list