![]() |
Confirm stop query string var code
I have a link beside each record in a list that when clicked, it calls the same page and passes ?delete=true
if my page sees the php $_GET["delete"] == true then it removes the record. Now I have a confirm dialog that pops up to tell them that if they do this, it cannot be undone giving them the chance to cancel. But as of now, the dialog comes up but it still passes the query string no matter if they hit ok or cancel. Can someone tell me how to stop or reset the delete query string from telling the page to remove if they hit cancel? Then place focus back on the form? here is my code Code:
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\">Code:
Code:
//here is my removal link (it is in a for loop with more than one) |
Code:
<SCRIPT LANGUAGE=\"JavaScript\" type=\"text/javascript\"> |
what? Is that not my exact code? Or did you add something?
|
I added a couple of brackets you missed out
|
Are you talking about on the else statement? I am confused...those brackets are not required for my code to work...Am I missing something?
The confirm dialog does come up, it does place focus back on the page...however what I need is if they Click cancel, for the query string ?delete=true to not equal true as this will tell my page to remove them anyway. So if they click on the delete link, and they choose cancel from the dialog, even though it still calls the same page, I need the delete var to not equal true or to stop the page from going to the URL of the link...either way. Does your brackets take care of this? |
oh ok, not sure, too tired
|
ok, that did not work...let me clarify. This link has nothing to do with the form that is also on the page. The form allows you the ability to add another company. While at the bottom of the page there is a list of the current companies in the system(which is a separate section) and by each there is a delete link that holds the ID of each company. If you click the delete link beside a company, it calls the same page, telling some php code to remove the record from the database. I want the link to prompt a confirm box(which it does) and if the cancel button of the confirm box is hit, then it places focus back onto the page and the php code never sees the $_GET["delete"] value because if it did, it would remove the record anyway. As of right now, the confirm box comes up and if you click on the cancel button, it still passes the delete query string and removes the record.
The last bit of code posted by bathurst_guy does not even bring up the confirm dialog box so I am restoring my code to the original posted code FYI. ***EDIT***well bathurst removed the code so nevermind the above remark, but I still need help :) Thanks again for your time and any help with this |
try
Code:
//form name is company |
I tried that...I thought that would work. I see what you are doing there. But unfortunately it still is passing the $_GET["delete"] from the link that I click to call that function.
Is there a programmatic way to set that "?delete=id" var equal to something else in that function if they clicked cancel in the confirm box? That way, I can check against it in the php if statement and if it equals say "nodelete" then It won't go in there... Thanks again for your help. Any ideas? |
It would be easier if rather than links you made them buttons and then return false would work. You can use CSS to style the buttons so that they still appear as a regular link if thats what you want?
|
This works fine...
PHP Code:
|
Pixeldepth,
Thank you first off for your help. I tried your code and I get the same results as I have been. What I have does popup the dialog box for confirmation and if you hit cancel, it does return you to the page. The issue I am having is that when you click the delete link it still passes id=1 (or delete=1 in my case) to the page and it tells my php code to remove the company with id of 1. If they hit cancel it needs to not enter the php code meaning the $_GET["id"] (or $_GET["delete"] in my case) needs to no longer hold the ID or needs to hold something else so I can prevent it from entering the removal function. I hope this clarifies what I am trying to do...I am running out of ways to explain it :) Bathurst...I think I will try the button idea next...not sure how to make a button look like a link though, but I can figure that out if your solution works... Thanks again for your time on this |
OK, I tried bathurst's idea using a button and here is my code so far
Code:
<js>then my buttons look like this Code:
<input type=button onClick=\"return doublecheck(".$row["ID"].");\" value=Delete>This gets no echo so even if I hit ok, it will not tell my remove code to work. SO this is getting the complete opposite results now. I alerted "comp" in the JS function and it does alert the companyID but I guess trying to pass a query string using Code:
document.location(\"../main/company.php?delete=comp\");Code:
if (!empty($_GET["delete"]))any ideas? thanks again for your help |
PHP Code:
PHP Code:
|
THanks for the reply...I am not sure what is going on now but I am getting the confirm box but no echo on the ok of the confirm box.
I added a form tag around the section that displys the current companies, added the code for the button like you posted and changed my php code to look for the post vars of the delete and I get no echo. Plus this solution has the value in the button set to the companyID which the buttons needs to say "Delete" not 4 or 2. So I am not sure I can do this... I need for the button or link to say "Delete" but pass the ID value to the same page when clicked. Here is my code now Code:
//PHP code at the top of my pageCode:
//form codeThank you again for your help |
| All times are GMT -5. The time now is 11:56 PM. |
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.