Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript confirm help

Status
Not open for further replies.

calv1n

Programmer
Sep 29, 2007
18
CA
U have this in the HEAD section of my web page:

Code:
<!--
function confirmation() {
	var answer = confirm("Are you sure you want to delete this folder?")
	if (answer){
		alert("Bye bye!")
		window.location = "[URL unfurl="true"]http://www.google.com/";[/URL]
	}
	else{
		alert("Thanks for sticking around!")
	}
}
//-->
</script>

Now I have this for my drop down menu:

Code:
echo "<form name=\"$formname\">";
echo "<td class=\"row\">";
echo "<br><select name=\"dropdown\" onChange=\"location=document.$formname.dropdown.options[document.$formname.dropdown.selectedIndex].value;\" value=\"GO\">";
echo "<option selected>-------------------</option>";
echo "<option value=\"cp.php?action=browse&path=$line\">Browse</option>";
echo "<option value=\"cp.php?action=add&path=$line\">Add Folder</option>";
echo "<option value=\"cp.php?action=rename&path=$line\">Change Name</option>";
echo "<option value=\"cp.php?action=upload&path=$line\">Upload</option>";
echo "<option value=\"cp.php?action=delete&path=$line\" onclick=\"confirmation()\">Delete Folder</option>";
echo "</select>";
echo "</td>";
echo "</form>";

So bascially when someone clicks on Delete Folder, I want the JavaScript to confirm the action. It kind of works. What I mean by that is if I click on Delete Folder, at the same time, it displays the popup and redirects me to the link.

Can someone please help me correct this problem?

Thank you.

-CALV1N
 
Sorry, I don't know how to use JavaScript. :-(

-CALV1N
 
Hi

And I do not know what that mess is. Please do not post server-side code. Next time paste the generated HTML from your browser's View Source window.

Anyway, with this modifications should work :
Code:
<select name="dropdown" onchange="if(this.options[this.selectedIndex].text!='Delete Folder'||confirmation())location=this.options[this.selectedIndex].value">

[gray]// ...[/gray]

<option value="cp.php?action=delete&amp;path=$line">Delete Folder</option>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top