-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeremy Bunton wrote:

> I want to set a javascript var to a coldfusion variable, what I am doing
> looks like below. The value being a true false Boolean. I keep getting an
> error that doit is undefined in CF. I've gone from coldfusion to JS before,
> but not the other way around. Thanks
> 
> Jeremy
> 
> <script>
> var doit = confirm("Are you sure you want to delete?");
> <cfset didit = doit>
> 
> </script>

You can't.

You see, the thing here is that when you thought you were assigning a
value from a ColdFusion variable to a JavaScript one, all you were doing
was generating some JavaScript code for doing the assignment. This gets
sent to the browser and executed. The only thing the Client and Server
know in common is HTTP.

JavaScript doesn't know about ColdFusion, and vis versa. If you want the
browser to execute some code on the server, you need to send a request
back to it, sort of as follows:

<form method="post" action="/page/to/execute.cfm">
<input type="hidden" name="id" value="5432" />
<input type="submit" value="Delete" onclick="return ConfirmDelete()" />
</form>

<script type="text/javascript">
function ConfirmDelete()
{
    return confirm("Are you sure you want to delete?");
}
</script>

[Aside: I don't use onclick myself, preferring to add handlers
unobtrusively.]

K.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCf3X8mSWF0pzlQ04RArq0AKDomXZjOplRYkA9/6hxFqh61zGa6ACgyECC
nFoY6fae1o+r41PsTamg8wo=
=Ozvu
-----END PGP SIGNATURE-----

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:206060
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to