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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript submit not working in IE

Status
Not open for further replies.

cfsponge

Programmer
Feb 22, 2006
44
US
I have two distinct functions that JS is performing for me. One is a prompt window and the other a basic submit. Neither works in IE, but I don't receive any errors or warnings (it works like a charm in Firefox).

<script type="text/javascript">
function ef(fp, action) {
f = document.forms['editFolder'];
f.elements['current_folder'].value = fp;
f.elements['folder_action'].value = action;
//If deleting, confirm
if (action == "delete") {
var answer = confirm("Are you sure you wish to delete this folder?");
if (answer) {
f.submit();
}
} else {
var folderName = prompt("Rename folder to:", "");
if (undefined != folderName) {
f.elements['foldername'].value = folderName;
f.submit();
} else {
alert("Folder rename cancelled.");
return false;
}
}
}

function nf(fp) {
f = document.forms['editFolder'];
f.elements['current_folder'].value = fp;
f.elements['create_folder'].value = 0;
var folderName = prompt("Please enter the new folder name.", "");
if (undefined != folderName) {
f.elements['foldername'].value = folderName;
f.submit();
} else {
alert("Folder creation cancelled.");
return false;
}
}
</script>



<form action="foo.bar" method="post" name="editFolder" id="editFolder">
<input type="hidden" name="root_folder" value="/customer_uploads/" />
<input type="hidden" name="expand_folder" value="0" />
<input type="hidden" name="current_folder" value="" />
<input type="hidden" name="folder_action" value="" />
<input type="hidden" name="create_folder" value="" />
<input type="hidden" name="foldername" value="" />

<a href="javascript://" onClick="ef('%2Fcustomer_uploads%2F2006','delete')">Delete</a> | <a href="javascript://" onClick="nf('%2Fcustomer_uploads%2F2006','edit')">New Subfolder</a>
 
No, because I have similar scripts that work perfectly in IE w/o touching my existing security level.
 
add a return false to your onclick.

Code:
<a href="javascript://" onClick="ef('%2Fcustomer_uploads%2F2006','delete')[red]; return false;[/red]">Delete</a> | <a href="javascript://" onClick="nf('%2Fcustomer_uploads%2F2006','edit')[red]; return false;[/red]">New Subfolder</a>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That was the key. Thank you, cLFlaVA.

As a side note, what is it about 'return false' that triggers IE correctly?
 
you have a href specified. href specifies where the link should take you. if there is garbage in the href, such as [tt]javascript://[/tt], the page will bring itself to the top, much like when there's a [tt]#[/tt] in the href. adding the return false means "act like the link was never clicked". i usually do something like this, because i think it's cleaner:

Code:
<a href="#" onclick="doFunction(); return false;">Click</a>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top