Coldfusion cfoutput a javascript variable

How can I use the javascript variable: total and use it as a Coldfusion cfoutput variable.
function UpdateCost() 
  					var total = 0;
  					var itemCount = document.getElementById('itemCount').value;
  					for (var i=1; i<=itemCount; i++) 
    					var elem = document.getElementById("trans"+ i);
    					if (elem.checked == true) 
						{ total += Number(elem.value); }
  						document.getElementById('totalcost').value = total.toFixed(2);

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why would you want to? I can see the other way around but I do not understand what you are trying to do. You should be able to do the whole thing in JS.
smares32371Author Commented:
The script is adding the check boxes that are checked with a dollar amount.

this here below outputs that total amount selected

 <input type="text" id="totalcost" size="10">

I need to grab the totalcost and then pass it as a hidden value to my payment form thats why i need to cfoutput the variable..
You have hidden input values right? If that is the case why not have JS populate the value?
I agree, the question doesn't really make sense because it has the proposed solution as part of the question - but the proposal not right - you can't use coldfusion on the client side with javascript.  

I think you need to restate your question as to what you are trying to accomplish, leaving out the "how"

For example, "I use javascript to determine the total cost" I need to update the database with this value or I want to display this value on the web page without a form post or....

If you have a form variable (such as a hidden input tag) all you have to do is submit the form to get it back to the server and be handled by Coldfusion again, then CF can insert it into the database.

ZvonkoSystems architectCommented:
"I need to grab the totalcost and then pass it as a hidden value to my payment form thats why i need to cfoutput the variable.. "

You have a page with this form field:
 <input type="text" id="totalcost" size="10">

And you need to pass that field by JavaScript to another page, right?
If you submit the page to ColdFusion server then you get that field value and need no JavaScript.

If you do not submit but call same ColdFusion page and want to pass the totalcost to the next page then are there several methods.

Therefore explain please in more details where you need that value totalcost to be handled and how the paymant page is initiated.

The JavaScript access to form field value is as easy as this:

Upper lines work on the page where your totalcost field is located but only when placed AFTER the totalcost field or after page load being finished.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.