Forum Moderators: open
>> and thus available to my CF tags
Hmm. Give me a brief overview of ColdFusion, and I might be able to help you!
The array isn't part of the document, if you like. It's actually a property of the window (global object). I don't know if that helps at all...?
>> the context of the script
There isn't really such a thing (#1). Once all scripts have loaded & executed, then it all becomes part of the Javascript object model (loosely).
#1 The one difference is that, if you execute a function call as the page loads, you can only call a function in a statement 'below' the function's definition if it is within the same script block/file. There is some worry about scripts arriving in the wrong order. If the whole scripting caboodle is only initiated onload, then none of this is an issue.
<script language="javascript">
var myArray = new Array();
myArray[0] = "test";
</script>
To pull a variable into coldfusion, I would usually do something like:
<cfset myVar = myArray[0]> <!--doesn't work-->
So, I know I need something more than myArray[0] here. Cfset does run on the server will pull things in from forms I create, so I think I just need the right way to reference myArray[0]. thanks
If so, what does it actually turn into?
Can I question this?:
>> the page goes to the server which knows how to parse the cf tags.
When a form is submitted, it can send information contained in its input fields etc. The whole page doesn't get sent back to the server. I can imagine a scenario where a browser could choose to send information in CFML tags as well, but that scenario requires the browser to understand CFML . I'm sure most browsers don't.
The CFML gets parsed by the server, but before the document is transmitted, surely?
#1 or the document is scripted to read the CFML tags, then create hidden form inputs etc. and that doesn't sound right for something as serious as CF.
So, if page1.cfm was:
<html>...
<cfset myVar = "Hi">
<cfoutput>#myVar#</cfoutput>
...
</html>
the user would see
<html>...
Hi
...
</html>
I have a JS function that will add variables to an array, myArray[0],[1],... In this case, page1.cfm will have a form with an action directing it to page1action.cfm. So I'll have the js array on page1.cfm, I would like page1action.cfm to see and process those variables.
>> the server runs any cf tags and then renders up html
So, the CFML tags are turned into script and HTML. No CF tags are left behind in the final out to the client (I still reckon). I suppose this question could be answered by doing a view > source on a page in a browser that has been processed by CF on the server.
Pudding proof.
Sticky me a URL if you have one.
The gist is that, if you have your tag:
<cfset myVar = myArray[0]>
This is processed on the server before myArray has been defined - as it's defined in the client. Do you know what kind of HTML is finally output by this tag?
I can imagine how it would all pull together, but seeing just in what manner it's going wrong may help (the actual current output). It may be something as simple as the value needing to be quoted - presumeably CFML is XML compliant.
Right, this happens before this gets to the client which is why this statement won't work. Let me ask you this (and thank you, you've been great to help), as I can pass form information onto my next CF page (page1action.cfm), if I have a form on the client's first page (after rendering by CF), would there be a way to assign myArray[0] to a hidden input tag within my form (preferably by looping through the array and dynamically creating all the tags I would need)?
say:
<form>
<input type="hidden" name="var0" value="myArray[0]">
<input type="hidden" name="var1" value="myArray[1]">
if so, on page1action.cfm, then I could say:
<cfset myvar0=#form.var0#>
<cfset myvar1=#form.var1#>...
The number of variables in the array will change, so I'd need to dynamically generate the input tags.
Thanks again.
to a hidden input tag within my form (preferably by looping through the array and dynamically creating all the tags I would need)?
Yes, definitely.
Let me have a look again. Meanwhile,
- What are the the values (in meaning) - strings or numbers (both)?
- Is there the CF version of the javascript, eval, where you can execute code/data structure that is input as a string?
var NewMessage =
CMNum + " " +
CMStartDate + " " + ... +
'<input type="Hidden" name="CMVar' + CMCount + '" value="' + CMNum + '">' +
'<input type="Hidden" name="CMVar' + CMCount1 + '" value="' + CMStartDate + '">' + ...
CMOutMessage = CMOutMessage + NewMessage;
CMOut.innerHTML = CMOutMessage;
Then on the page1action.cfm, you can access the first variable as <cfset CMNum = #form.CMVar1#>
So again thanks, you got me on the right track.