Time:
Scotland: Fri, 9:33 pm
Rhode Island: Fri, 4:33 pm
Florida: Fri, 4:33 pm
New Mexico: Fri, 2:33 pm
California: Fri, 1:33 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : passing server side variable


burney
03-09-2004, 06:56 PM
hi,

I am using coldfusion as server side language.
i have a variable defind as
<cfset i=0>

<cfset i= i+1>
..


now i want to pass the value of i to javascrip when submitting the form. As i want to do some validation. but when i try to pass this varaible it gives me error saying undefined. so how can i pass this variable to javascript.

Thank You
Faiz Burney

KH@
03-10-2004, 12:52 PM
Not sure if I understand the question but...

If you set a CF variable it is processed server side then the javascript is processed client side. To covert a CF variable to JS variable simply declae it.

So maybe this is what you are after

<cfset i=0>

<cfset i= i+1>

<cfoutput>

<script>

var i=#i#;

</script>

</cfoutput>

Worth a try

:)

vksrinu
11-26-2004, 07:51 AM
hi kh

the code which you given will works fine when the page is loading, but if want to check some validation depending on the user data entry it is not possible. then we may need to write that code in the next page, that we can do it in the general way also.

Srinivas

KH@
12-07-2004, 01:43 PM
Hi, What I mean is,

CF is a serverside script so all CF stuff is done at the server, then after processing the resulting code is sent to the client/visitor.

You can therefore get CF to declare its own variables (FORM CGI SESSION APPLICATION CLIENT CALLER ATTRIBUTES) as javascript variables and then use them within javascripts client side.

If you just want to do form fiel;d validation before a form is submitted to the server then you will only be using javascript and CF hardly comes into it unless you wish to use the CF built in Form Field Validation scripts produced by the CF FORM Element tags. EG.

<cfform action="thispage.cfm" method="POST" enablecab="Yes" name="daForm">

<cfinput type="Text" name="numberOf" message="You did not type in a number" validate="integer" required="Yes">

</cfform>

You probably need to ask about form validation in the JavaScript Forum.

Otherwise you can submit the form to the server, validate serverside with CF, then redirect back to error page if input is incorrect.

This is not the best way as it needs a trip to the server. The best way is to validate client side with javascript