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

Javascript Result to CF Variable 1

Status
Not open for further replies.
Nov 12, 2003
22
0
0
US
I am a newbie, so hopefully this will be an easy question. I am working on a support site for our organization. I have a simple javascript that will pull the local time from the client system. This, along with other info, is to be dumped into an e-mail using cfmail and sent to our support staff. The script is this:
<script language="javascript">ourDate = new Date();
document.write("Client Local time is " + ourDate.toLocaleString() + ".<br/>");
</script>
The problem is, if I try to put this into a CF variable, it puts the script in as a text string rather than giving me the result. Any thoughts on how I can just put the result into a variable?

Thanks,
STelljohann
 
you can't, at least not the way you are trying it- CF is processed on the server, before the javascript is processed on the client, so when the CF is parsed there are no Javascript variables created yet. The only way I know of is to put the value from javascript into a hidden form variable and submit it to the page which does the CFMAIL. or use cookies, but either way i don't think you are going to be able to access your javascript variables from CF on the same page they are created.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
>>i don't think you are going to be able to access your javascript variables from CF on the same page they are created

there is a workaround, u have to use IFRAMES, the iframe can call the Mail.cfm file and also access javascript varaibles...

Known is handfull, Unknown is worldfull
 
Thanks for the input. Below is the form that accepts user input. It dumps the info into a second page "support_problem_email.cfm" wich then does the cfmail piece. How would I incorporate the javascript into this form in order to pass the value correctly. Thanks for your help.


<form action = "support_problem_email.cfm" method = "post">
<pre>
First Name:<input type="Text" name="FirstName" size="30">*
Last Name:<input type="Text" name="LastName" size="30">*
E-Mail Address:<input type="Text" name="MailFrom" size="30">*
Phone Number:<input type="Text" name="PhoneNum" size="30">
City:<input type="Text" name="City" size="30">
State:<input type="Text" name="State" size="2">
Country:<input type="Text" name="Country" size="30" value="United States">

I Prefer to Be Contacted by:<select name="ContactBy">
<option value="Contact By E-Mail">E-Mail
<option value="Contact By Phone">Phone
<option value="No Contact Requested">No Contact Requested
</select>

<input type="checkbox" name="BrowserCleared" value="Yes">I have cleared my browser's cache, and still have the issue
<input type="checkbox" name="OtherSuccess" value="Yes">I have successfully [accessed this site/performed this action]
on my computer previously.
<p>
<font face="arial" size="-1">* Denotes a required field.</p></font>
<hr>
<font face="Arial">Please give a brief description of your issue:</font>
<textarea name="body" cols="50" rows="7" wrap="virtual"></textarea></pre></p><!--- establish required fields --->
<input type="hidden" name="FirstName_required" value="You must enter your first name">
<input type="hidden" name="LastName_required" value="You must enter your last name">
<input type="hidden" name="MailFrom_required" value="You must enter your e-mail address">
<input type="hidden" name="Body_required" value="You must enter some text">
<p>
<input type="Submit" name="" Value="Submit Problem Report">
<input type="Reset" name="" value="Clear Form"></p>

</form>

-Stelljohann
 
i do not fully understand ur query, but i can give u an example:

<script>
TheJsVal="Hey"
</script>

<iframe name="MailFrame" src="Test.html" frameborder=0></iframe>


Test.html:
<html>
....
<script>
alert(parent.frames.TheJSVal)
</script>

Known is handfull, Unknown is worldfull
 
yes you can use Iframes, but keep in mind they are supported by IE and NN6.0 only (last i checked) which puts them at about 90% of web browsers, they're fine if you are in control of the browser you audience uses, but if it's public- i wouldn't use them.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
We are not using frames. Our customer machines are way too diverse. Basically, I am just trying to retrieve the client's local time in the background and include that time in the body of a cfmail. The mail includes items that the client will input, and the local time will help us with troubleshooting. I also dump the local time of our CF server into the e-mail. This will give the support staff a reference when trying to address the issue.

Thanks for your continued input.
 
iframes is not just a frame its basically a page in a page, sp u need not worry about any frame problems...

Known is handfull, Unknown is worldfull
 
you could pass the current date and time with the form submission to the email page like so:
Code:
<script language="JavaScript"><!--
function stamp() {
    document.myForm.dateandtime.value = new Date();
}
//--></script>

<form action = "support_problem_email.cfm" method = "post" onSubmit="stamp()" name="MyForm">
<pre>
First Name:<input type="Text" name="FirstName" size="30">*
Last Name:<input type="Text" name="LastName" size="30">*
E-Mail Address:<input type="Text" name="MailFrom" size="30">*
Phone Number:<input type="Text" name="PhoneNum" size="30">
City:<input type="Text" name="City" size="30">
State:<input type="Text" name="State" size="2">
Country:<input type="Text" name="Country" size="30" value="United States">

I Prefer to Be Contacted by:<select name="ContactBy">
<option value="Contact By E-Mail">E-Mail
<option value="Contact By Phone">Phone
<option value="No Contact Requested">No Contact Requested
</select>

<input type="checkbox" name="BrowserCleared" value="Yes">I have cleared my browser's cache, and still have the issue
<input type="checkbox" name="OtherSuccess" value="Yes">I have successfully [accessed this site/performed this action]
on my computer previously.
<p>
<font face="arial" size="-1">* Denotes a required field.</p></font>
<hr>
<font face="Arial">Please give a brief description of your issue:</font>
<textarea name="body" cols="50" rows="7" wrap="virtual"></textarea></pre></p><!--- establish required fields --->
<input type="hidden" name="FirstName_required" value="You must enter your first name">
<input type="hidden" name="LastName_required" value="You must enter your last name">
<input type="hidden" name="MailFrom_required" value="You must enter your e-mail address">
<input type="hidden" name="Body_required" value="You must enter some text">
<p>

[b]<!--- ADDED HIDDEN FORM FIELD --->
<input type="hidden" name="dateandtime">[/b]

<input type="Submit" name="" Value="Submit Problem Report">
<input type="Reset" name="" value="Clear Form"></p>

</form>

then you will have #FORM.dateandtime# available for use in CFMAIL.


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
nice,
got carried away the thought that the submitting of the mail should be in the same page...

Known is handfull, Unknown is worldfull
 

Excellent! Thank you, that worked. The only tweak I had was to add a value parameter and it works like a charm.


<input type="hidden" name="dateandtime" value="">



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top