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

Reference CF Variables in Javascript

Status
Not open for further replies.

scripter73

Programmer
Joined
Apr 18, 2001
Messages
421
Location
US
Hi,

I'm having trouble resolving a Cold Fusion variable in Javascript.

Basically I have the following:

<script language=&quot;Javascript&quot;>
<!--
function populate_contact2(){

document.form2.vo_fname.value=<cfoutput>#form.firstname</cfoutput>


//-->
</script>


Basically this function will be called from a form when a user checks a box.

The error I get is the standard &quot;Syntax error on the Cold Fusion variable value&quot;. Form.firstname exists.

Please advise.

Thanks,
scripter73
 
Well, scripter

If the code you posted is exactly what you're using the problem is the second #

Compare this:

document.form2.vo_fname.value=<cfoutput>#form.firstname#</cfoutput>


IF that is not the problem please post your exact code and we'll try again.
 
Where is the variable form.firstname coming from, the same page, or a previous page?
- tleish
 
Hi All,

Well sorry about the typo, but I do indeed have the following in my Javascript:

document.form2.vo_fname.value=<cfoutput>#form.insured_fname#</cfoutput>;

The #form.insured_fname# is being passed to this .cfm file from a previous form in a previous .cfm page. The data does indeed reach my current page because when I say:
Insured Fname: <cfoutput>#form.insured_fname#</cfoutput><br>, I'm able to see my data.

????

Thanks in advance,
scripter73
 
I think that you will have to put your value into a hidden field. Then javascript can access the field if it is within a <form> and it has a name.

<script language = &quot;javascript&quot;>

myvar = document.main.myvar.value;

</script>

<form name=&quot;main&quot; .....>

<input type=&quot;hidden&quot; name=&quot;myvar&quot; value=&quot;<cfoutput>#...... #</cfoutput>&quot;>


</form>
 
I know this post was a while ago, but just in case anyone else has a similar problem...

Try :
Code:
document.form2.vo_fname.value='<cfoutput>#form.insured_fname#</cfoutput>';

Notice the single quotes around the variable.
 
Thanks, Joe.

I always go back and refer to my posts.

I found a way around it at the time, but I appreciate your help.

Thanks again,
scripter73
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top