Cfscript
I have a client side button that, when clicked, links to a
server side page with delete queries. However, I must give the user
a confirmation message making sure they really want to delete the
current record. I am attempting to perform this via JavaScript
within <cfscript> tags. However, I am having some troubles.
Below is the code....the first part is in the <head> section
(CR4203.cfm is the server side page with the deletion queries), and
the button itself is in the <body>. Any ideas how to get this
working, or a new approach I can take???
<cfscript>
function ConfirmDelete() {
if (confirm("Click OK to Delete this CR.")) {
window.location="CR4203.cfm";
</cfscript>
<cfscript>
<input type="button" name="Delete" value="DELETE CR"
onclick="ConfirmDelete()">
</cfscript>
This should do it
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head><title>delete test</title>
<script type="text/javascript">
function ConfirmDelete() {
if (confirm("Click OK to Delete this CR.")) {
window.location="CR4203.cfm";
</script>
</head>
<body>
<form>
<input type="button" name="Delete" value="DELETE CR"
onclick="ConfirmDelete()">
</form>
</body>
</html>
Similar Messages
-
I've got a function in a CFC that inserts a parent value into
an Oracle table (see below). I want to extend the function to
return the new parent ID so that I can use it to insert the child
values. I'm using <cfscript> to execute the function which
works fine with the data insert, but I can't quite work out how to
output the new parent ID value in <cfscript>. Any help
appreciated.
Thanks in advance
Roy.
<cffunction name="insertApp" hint="Insert Applications"
returntype="query">
<cftry>
<!--- Insert Values --->
<cfquery name="qryAppInsert" username='#this.uid#'
password='#this.pwd#' datasource='#this.source#'>
INSERT INTO
impsapp.tblAPPLICATIONS
VALUES
(#this.ID#, '#this.dType#',
TO_DATE('#this.cDate#','dd-mon-yyyy'))
</cfquery>
<!--- Select current Value form DUAL --->
<cfquery name="qryNewSeq" username='#this.uid#'
password='#this.pwd#' datasource='#this.source#'>
SELECT impsapp.Test_SEQ.currval x FROM dual
</cfquery>
<cfcatch type="any">
<cfreturn "Error in Function insertApp">
</cfcatch>
</cftry>
<!--- Return Query --->
<cfreturn qryNewSeq>
</cffunction>
<cfscript>
// create componet object
comTest = createObject("component", "cfc.Test");
// Set the properties from Form
comTest.uid = '#myUser#';
comTest.pwd = '#myPasswd#';
comTest.source = '#myDS#';
comTest.holder= #Form.eID#;
comTest.appType = '#Form.pType#';
comTest.recDate = '#DateFormat("#Form.dateReq#",
"dd/mmm/yyyy")#';
//Call insert finction
apply_Card.insertApplications();
//I need to be able to output and use the value x from the
qryNewSeq above
</cfscript>YourQuery = comTest.insertApp();
Your function might be too complicated. If this.id is the
same as test_seq.currval, why bother with the second query? -
I need to add " " within a sentence inside my CFscript. When
I applied it, I got an error, it seems that CFScript doesn't like
the extra "" within "". What should I do so the word "Warning"
appear to user within this double quotes
<CFSCRIPT>
.......some codes here
structFormText[numKey][1]["formText"] = "I have some text
here and I need to put double quotes surrounding a word within this
sentence so that my user will be able to see "Warning" like what
you are seeing now ";
................................some codes here
</CFSCRIPT>Yet another variation
<cfscript>
x="...my user will be able to see #chr(34)#Warning#chr(34)#
like what you are seeing now ...";
</cfscript>
<cfoutput>#x#</cfoutput> -
File upload from form using cf8 file functions within cfscript?
essentially, i'm wondering if anyone can give me an example
of a way to replicate cffile upload using cf8's native file
manipulation functions within a cfscript tag?
more specifically, i am wondering if anyone had any code
examples for uploading a file specified by a user on an html form
using cf8's file functions (fileOpen, fileCopy, fileDelete,
fileMove, fileClose, etc....) within a cfscript tag. i've done this
a number of times in the past using upload through cffile, but i'd
like to take advantage of cf8's new native file functions and be
able to deploy the code within a cfscript block.
i've found some simple examples of the file functions within
the docs and online, but nothing showing me how to take a file from
an html form and upload it where i want it, as cffile will do.
thanks in advance for any help.those cf8 file functions are for manipulating files on the
server.
you still need to upload the file in one way or another.
as for replicating cffile action=upload in cfscript: just
write a
function that uses cffile tag to upload a file, and call that
function
from your cfscript!
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/ -
Hi all,
I want to add to this code with an elseif
Will it work to put in before the else in the udf.cfm code
below the following? TIA:
elseif (referer contains 'yahoo.com')
StartPos=ReFindNoCase('q=.',referer);
if (StartPos GT 0) {
EndString=mid(referer,StartPos+2,Len(referer));
Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
Keywords=URLDecode(Keywords);
return Keywords;
udf.cfm
<cfscript>function getGoogleKeywords(referer) {
var Keywords='';
var StartPos=0;
var EndString='';
if (referer contains 'google.com') {
StartPos=ReFindNoCase('q=.',referer);
if (StartPos GT 0) {
EndString=mid(referer,StartPos+2,Len(referer));
Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
Keywords=URLDecode(Keywords);
return Keywords;
else {
return '';
}</cfscript>quote:
Originally posted by:
cf_dev2
> Will it work to put in before the else
Did you try it? An if / elseif / else works the same as a
cfif/cfelseif/cfelse.
Really?
I always use two words, "else if"
Guess there's always more than one way that works. -
i am looking for an example of using cfscript to pass varibles into a query and NOT HARDCODED into the addParam value attribute.
Sugesstions ?You could just create your own custom function. To illustrate, take the following example from the documentation:
<cfscript>
queryService = new query();
queryService.setDatasource("cfdocexamples");
queryService.setName("getParks");
queryService.addParam(name="state",value="MD",cfsqltype="cf_sql_varchar");
queryService.addParam(value="National Capital Region",cfsqltype="cf_sql_varchar");
result = queryService.execute(sql="SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE = :state and REGION = ? ORDER BY ParkName, State ");
getParks = result.getResult();
</cfscript>
<cfdump var="#getParks#">
You could customize it as follows:
<cfscript>
queryService = new query();
queryService.setDatasource("cfdocexamples");
queryService.setName("getParks");
qParams = getQueryParams();
result = queryService.execute(sql="SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE LIKE '#qParams.stateFirstLetter#%' and REGION LIKE '#qParams.regionFirstLetter#%' ORDER BY State, ParkName");
getParks = result.getResult();
function getQueryParams() {
var myParams=structnew();
myParams.stateFirstLetter = "M";
myParams.regionFirstLetter = "N";
return myParams;
</cfscript>
<cfdump var="#getParks#"> -
Cfscript I'm trying to write Please help :)
I wonder if some one could help with a cfscript I'm trying to write.
A have a number eg
135
4245
1
I want to turn these into a string with length 6 with zeros at the start like so:
000135
004245
000001
thx 4 any ideasHere's a cfscript along the lines of what you asked for. There's other ways to do it, of course, but I thought this approach would be helpful to you.
<cfscript>
/* takes a string as an argument and adds as many zeroes as it takes to make the string be exactly 6 characters. */
function PadWithZeroes()
var VarToTest = "";
var ValToReturn = "";
var VarLen = 0;
var DesiredVarLen = 6;
if (StructCount(Arguments) EQ 1)
/* Use Trim(Arguments[1]) only if you do NOT want to add zeroes to one or more empty spaces */
VarToTest = Trim(Arguments[1]);
VarLen = Len(VarToTest);
TimesToLoop = DesiredVarLen - VarLen;
if (TimesToLoop GT 0)
for (q = 1; q LTE TimesToLoop; q = q + 1)
VarToTest = "0" & VarToTest;
ValToReturn = VarToTest;
return ValToReturn;
else
return false;
// the rest is for testing/viewing the function etc.
NumberToUse = 4;
if (IsDefined("URL.NumberToUse") AND Len(Trim(URL.NumberToUse)) LTE 6)
NumberToUse = Trim(URL.NumberToUse);
</cfscript>
<cfoutput>
<br>
NumberToUse=#NumberToUse#
<br>
<br>
PadWithZeroes(NumberToUse) = #PadWithZeroes(NumberToUse)#
<br>
<br>
</cfoutput> -
Is CFMail and Mail (CFScript) the same?
Is CFMail and Mail (CFScript) the same.... Reason I ask, is we are having a tonne of email problems in our application. A person on my team has indicated that cfmail is more reliable and all the cfsript, "mail" implementations remain largely undelivered. For this reason they are requesting the we change everything from mail to cfmail. Has anyone heard ot this before? I've got to believe that under the covers these are running the same bits of code...?
CF10
RHEL 6.2
Thanks
Leelol, Thanks Adam!
This is what he is observing...
---This issue lays outside our system. Each mail sending mechanism results in a different SMTP message which gets routed differently. We have issues with the reverse DNS lookup, the MX records, and other stuff. If everything is correct and in place, it shouldn’t matter which mail mechanism we use in ColdFusion, but <cfmail> messages appear to be more successful in getting through.---
I'm going to try and confirm the nature of the DNS issues and other stuff, but still can't see these even routing differently based on what you are saying.
Cheers
Lee -
CF9 cfscript documentation/examples?
I am in the process of updating the CFML mode in the editor I use for CF development and have spent some time going through the available CF9 documentation. In looking through the downloadable PDFs, I am trying to find either examples or reference material for some of the new stuff and have failed. For example, the "Developing Applications" document, on p. 105-108 lists a number of CFML tag/CFSCRIPT equivalents (some of which are indicated as being new) for which I can find no examples or references describing the syntax or what they look like:
savecontent
trace
location
Can someone point me either to examples or (preferably) to reference material for these elements of CFSCRIPT?
In addition, in looking at exception-related topics in CFSCRIPT, I'm wondering about throw. How does "throw" in CFSCRIPT compare from CFML? p. 18 of the "Developing Applications" document has a single example of
throw "message";
but I'm wondering what throw really looks like in terms of the other attributes (detail, errorCode, extendedInfo, message, object, type).
Is Adobe actively working on the CF9 documentation? These aren't the only areas I have found in trying to go through the docs to see what is new, changed, etc., where they seem a little fuzzy or incomplete, but maybe I'm just not looking in the right places.
Thanks in advance.
/ronThanks for the follow up, Adam. I'll look some more at the throw() stuff to see if I just missed it in the docs.
Given all of the changes to CFSCRIPT in CF9, I would have thought having decent docs would have been a priority for Adobe, particularly given the nature of the changes. I've always liked CFSCRIPT for logic, but have wanted a more complete coverage of the capabilities available via the CF tags to also be available in CFSCRIPT; as a result, I've really been looking forward to CF9 with that in mind.
I've got to say, however, that the expansions to CFSCRIPT feel very ad hoc: poor (as in incomplete, in error, and inconsistent in coverage and format) documentation and lack of consistency in how the expanded coverage is provided: some via component, some via function, and some via a couple of different formats of statement.
I'll keep digging in the docs, and I'm hoping to have a CF9 box fairly soon to start trying some of this against to verify syntax.
/ron -
CFScript Math expression - Summing up looped over data
If I loop over numeric data and I want to sum that data I am looking for the correct manner to do so. Of course I want to do this in cfscript.
I know that I could go the route of doing a one demensional array and using the array sum function and I could also use stauctures.
I am interested in different solutions to this problem.
My end state is that I need to sum and average looped dynamic data for reporting purposes.
For purposes of example static values will be helpful for better understanding.
Thanks in advance.Owain,
This is what I came up with and it outputs the looped data. Now I am trying to add it up and average the results.
BTW Adam,
Be delusional on a Microsoft or Oracle forum board.
Now that would be some fun reading cutting through those flames! (In a patronising Kinda Way!). -
Need help... Context validation error for tag cfscript.
Code:
<cffunction name="computeHash" access="public" returntype="String">
<cfargument name="password" type="string" />
<cfargument name="salt" type="string" />
<cfargument name="iterations" type="numeric" required="false" default="1024" />
<cfargument name="algorithm" type="string" required="false" default="SHA512" />
<cfscript>
var hashed = '';
var i = 1;
hashed = hash( password & salt, arguments.algorithm, 'UTF-8' );
for (i = 1; i <= iterations; i++) {
hashed = hash( hashed & salt, arguments.algorithm, 'UTF-8' );
return hashed;
</cfscript>
</cffunction>
Error on web app:
Context validation error for tag cfscript.
The start tag must have a matching end tag. An explicit end tag can be provided by adding </cfscript>. If the body of the tag is empty you can use the shortcut <cfscript .../>. The CFML compiler was processing:
a cfscript tag beginning on line 11, column 12.
a cfscript tag beginning on line 11, column 12.
The error occurred in xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\salty.cfc: line 11
9 : <cfargument name="iterations" type="numeric" required="false" default="1024" />
10 : <cfargument name="algorithm" type="string" required="false" default="SHA512" />
11 : <cfscript>
12 : var hashed = '';
13 : var i = 1;
I am completely lost on why it's fumbling with why it says there's no closing tag. Help!!!!
ThanksWhat's on lines 1-7 of that file?
That code compiles fine for me on CF8 & CF9, so that's not where the error is.
You're not trying to compile it on any earlier version of CF than CF8 are you? The < and ++ operators are not valid prior to CF8. CFMX7 might see the < as a stray angle bracket, and get confused. I don't have CFMX7 running here to test the exact error that would produce, sorry.
Adam -
I would like to use cf tags inside cfscript, for example
cfquery and cflocation. What is the best way to achieve this.
CheersHere is the way to use cfquery within cfscript
<cfoutput>
<CFSCRIPT>
SQLString = "<!---Your Query Here --->";
DATASOURCE = "<!---Datasource here --->";
checkUser = CFQUERY(SQLString: SQLString,DATASOURCE:
DATASOURCE);
if (checkUser.recordCount neq 0)
WriteOutput("Welcome Back, " & checkUser.first_name);
else
WriteOutput("Your UserName is Wrong.. try again!");
</CFSCRIPT>
<cffunction name="CFQUERY" access="public"
returntype="query">
<cfargument name="SQLString" type="string"
required="yes">
<cfargument name="Datasource" type="string"
required="yes">
<cfargument name="dbType" type="string" default="">
<cfquery name="RecordSet"
datasource="#arguments.Datasource#" dbtype="#arguments.dbType#">
#preserveSingleQuotes(arguments.SQLString)#
</cfquery>
<cfreturn RecordSet>
</cffunction>
</cfoutput>
thanks
Satyajit Behera
MindfireSolutions,
Bhubaneswar -
Help:Function call from CFScript
I need to write a function call within
<cfscript></cfscript> but not sure with the syntax. I
got error message with the suntax I wrote (see below).
All I need is for the function AddVal () to pass an Array
within the existing loop.
<CFSCRIPT>
//Existing codes
Function ExistingFunction(ParameterA) {
//some codes here
for ( i = 1; i LTE listLen( fileCon, crlf ); i = i + 1 ) {
//some codes was written here to generate a 2 dimensional
Array called: MyArray
// I need to write my function here, so on every loop it
will pass an array to be inserted to DB
function AddVa(MyArray); >>>>> ??????????????
<CFFUNCTION name="AddVal">
<cfargument name="MyVal" type="Array" required="true">
<cfquery name="MyQuery datasource="MyDatasource>
// insert statement here
</cfquery>
</CFFUNCTION>
</CFSCRIPT>pls try this.
//syntax to call a function inside cfscript is given below.
//variablename = functionname(pass ur argument);
change ur code like this.
<!--- First, clean up the CFSCRIPT block --->
<CFSCRIPT>
function ExistingFunction(ParameterA) {
//some codes here
for ( i = 1; i LTE listLen( fileCon, crlf ); i = i + 1 ) {
//some codes was written here to generate a 2 dimensional
Array called: MyArray
getIP=AddVal(MyArray);//syntax to call a function inside
cfscript.
</CFSCRIPT>
<!--- since you're doing a query move this function
outside the CFSCRIPT block
...you can still call it from your CFSCRIPT block --->
<CFFUNCTION name="AddVal">
<cfargument name="MyVal" type="Array" required="true">
<cfquery name="MyQuery datasource="MyDatasource>
// insert statement here
</cfquery>
</CFFUNCTION>
try this and inform. -
Hello Gurus
Wondering if this is possible?
(CFMX 5)
I have a cfscript function:
<cfscript>
function doSomething(thingToDo) {
return URLEncodedFormat(Encrypt(thingToDo,myKey));
</cfscript>
takes 'thingTodo', encrypts it with private key and then
makes friendly to use over URLs.
Now I want to pass in a JS variable instead of a raw string,
something like this:
<cfoutput>
<select name="selectObject"
onchange="javascript:location.href='somepage.cfm?#doSomething(this.value)#'">
<option value = "option1">Option 1
<option value = "option2">Option 2
</select>
</cfoutput>
so that thepage forwards to:
somepage.cfm?with_encrypted_js_variable_here
Is there a way to do this?
I have no hair left, so any pointers in the right direction
appreciated
JamNot sure if this is what your looking for but... how about
this?
Note: if you want to encrypt the values on the fly you'll
need to encode ( or encrypt ) through javaScript. I beieve the cold
fusion and javaScript are processed and run at different times.
<cfscript>
myKey = 'test';
function doSomething(thingToDo) {
return URLEncodedFormat(Encrypt(thingToDo,myKey));
</cfscript>
<script language="javascript">
function loadURL(str) { self.location.href = 'somepage.cfm?'
+ str; }
</script>
<cfoutput>
<select name="selectObject"
onchange="loadURL(this.value)">
<option value = "#doSomething('option1')#">Option 1
</option>
<option value = "#doSomething('option2')#">Option 2
</option>
</select>
</cfoutput> -
Hi,
It would seem that CF builder2 doesnt have any code assisting for cfscripting.?
Surely ive missed something here.
If this is the case then im wondering whats going on as DM CC is clearly trying to discourage you from using it for coldfusion (by stripping out previous CF tools).
CF builder has no code assist for cfscript..
i like to use cfscript in my components as I like the way it resembles other languages im familiar with, eg javascript, c# etc.
Im wondering now, why bother, just use the TAGS ank keep life simple?@advancesolutionsni: Code assist absolutely does work in script. What is an example of what’s not working for you? especially compared to something that “works” for you in tag syntax?
For instance, if you maybe want arguments of a function to popup for you, that does work. But do note that (in either tags or script) you need to click ctrl-space to make that work.
Same with seeing a list of available variables on a page when naming a variable on the right-side of an assignment, or seeing the list of available datasources defined in your CF Admin when creating a query, or seeing the list of CFCs when doing a createobject of a component, or seeing a list of methods in a CFC when referring to an instance of one, and so on.
BTW, those last four are things that DW never could do, and it just scratches the surface of such differences, so CFB really is much more than just “a different CF editor”. Each does things the other does not. We need to learn to use each tool to its max, and the way it works.
To that end, I would point out that there is a very substantial user guide for CFB, available online
http://help.adobe.com/en_US/ColdFusionBuilder/2.0/Using/index.html
And there’s a specific section on code assist, with more on the above, at:
http://help.adobe.com/en_US/ColdFusionBuilder/2.0/Using/WS0ef8c004658c1089-554789f8121af8f 0c8c-7ffb.html#WSd160b5fdf5100e8f-1264b51812d55ebda15-7ffb
HTH.
/charlie
Maybe you are looking for
-
I down loaded new OS X (Lion)operating system and discovered my CAD programs no longer run. Is it possible to reload the original OS X and remove Lion?
-
Problems with my iPhone gallery app (iPhone 4, OS 4.1). It was working fine, then I added two new albums with about 120 photos in each.... and now the app crashes. It appears to be booting properly, but when it starts the image scroll across the top
-
Reset Mail then setup to use Yahoo
Now that I can get emails from hotmail on my iphone, How can I get Hotmail email to work with mail on my macbook pro? My Mail has never worked properly. I'd like to start with a clean slate.
-
Does anyone know how to fix this issue? I deploy an EAR. The EAR deploys successfully using the web console. 3 session beans and 1 BMP entity bean. Session beans load and BMP does not. Because it does load I cannot access the BMP through JNDI call. A
-
Digital Camera with Quik Time 4 software won't work
Hello: i have Quik Time 4 as part of Olympus Digital Camera(Camedia)software and it will not work it this XP computer.( itused to) It works in my wife's XP computer and my Win 98se computer