A reader asks:
Howw can i make a reload page button with a cfform?
The answer is to use JavaScript. Flash Forms (and Flash in general) can communicate with JavaScript using getURL. This is a technique I use when I want to use Flash Forms to send the user anywhere, like maybe a detail page based on the current record selected in a grid. To reload though we can just use the JavaScript reload method. Here is the code:
<script>
function reloadThis() {
document.location.reload();
}
</script>
<cfform format="flash" height="50" width="200">
<cfinput type="button" name="reload" value="Reload" tooltip="Click here to reload."
onClick="getURL('javascript:reloadThis()')">
</cfform>
<cfoutput>
<p>
#randrange(1,100)#
</p>
</cfoutput>
The randRange at the end is just there to confirm the page is reloading. Of course, if you want to hard code a URL in, you can use this in your button:
<cfinput type="button" name="reload" value="Reload" tooltip="Click here to reload."
onClick="getURL('http://www.cnn.com')">
You could replace the CNN with the current URL of course.
I'm using this technique on a site now where the flash grid lets you click a button and download a file. The URL is hitting a page using cfcontent, so to the user, it looks as if you never left the cfgrid. You select an item, hit the Download button, and are then prompted to download a file. It works great.
Archived Comments
What's the difference between a reload and a submit?
A submit will send form data. That may or may not matter.
I would like to know what the syntax would be to add a url variable bound to the selected item of a grid. I tried onclick="getURL('ContactMgr.cfm?ContactID={gridContact.selectedItem.ContactID},'_blank')" but that just sends the literal string, not the value
ok, I think I figured it out using your November post about opening a new window. I have the javascript routine:
<!--- Javascript routine to open new window --->
<script>
function show(u) {
if(u != '') window.open(u, 'sub', 'directories=no, location=no, menubar=no, resizable=yes, scrollbars=no, status=no, titlebar=yes, toolbar=no, height=435, width=535')
}
</script>
Then I have a grid called "gridContact" and the ID for contacts is ContactID so the syntax for the onload event looks like this:
onclick="getURL('javascript:show(\'ContactProfile.cfm'+'?ContactID='+gridContact.selectedItem.ContactID+'\')')"
I am trying to utilize javascript for a confirmation to verify that the user wants to delete a record. The function I am using below is getting triggered. However, the submit is not submitting the form. I am assuming this should trigger whatever is in the action portion of the cfform tag? I just want to call another .cfm page once the user verifies they want to delete. I am using cfform format="flash" if that matters. Any suggestions would be greatly apprecitated.
<SCRIPT LANGUAGE="JavaScript"> function confirmDelete() {
var msg = "Are you sure you want to delete?"; if ( confirm(msg) ) { document.frmModifyPWarrior.submit()
}
}
</SCRIPT>