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
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
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
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.