Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CFinput, use the onclick method to do a cfset of a CF variable

Posted on 2004-03-25
11
Medium Priority
?
1,278 Views
Last Modified: 2013-12-24

I have this cfinput statement in a table so that I get as many rows as there are records in my query result.

<cfinput type="radio" name="SelectedDepartment" value= "#CountDepartmentStatus.DepartmentCode#" >

I would like to add the onclick option to it and  have the javascript routine do the following cfset.

<cfset client.DepartmentCode=CountDepartmentStatus.DepartmentCode>

Is there a way to execute a cfset from the onclick method of a cfinput?

Thanks,
WS
0
Comment
Question by:Waterstone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10683739
You can only call CF via JavaScript if you would call another document.

What is it exactly that you want to do?

Do you want to pass the selected option back to CF?

<form method="post" action="somefile.cfm">
<cfinput type="radio" name="SelectedDepartment" value= "#CountDepartmentStatus.DepartmentCode#" >
<input type="submit" value="submit">
</form>

Then in somefile.cfm you will have

<cfset client.DepartmentCode=form.SelectedDepartment>
0
 

Author Comment

by:Waterstone
ID: 10683881


I was hoping to set the cf variable without leaving the document.
0
 
LVL 5

Expert Comment

by:Seth_Bienek
ID: 10684490
Hi WS,

What are you wanting to do once the value is set?  Go to the results page?  Let the user make other selections, then hit a button for the results?

Tell us what you are wanting to accomplish and we can explain the best approach.

Take Care,

Seth
0
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
LVL 17

Expert Comment

by:Tacobell777
ID: 10685005
You can only do that if you use hidden frames or Iframes....
0
 

Author Comment

by:Waterstone
ID: 10686058


Good Morning,

I'd like to set the value and reset the value as desired, then allow the user to select from the navbar menu to go to a number of different pages.

The navbar contains graphics as menu items that are consistent with the rest of the site. Forms restrict me to a standard button look that violates the design of the site.

Never used hidden frames or I frames.

WS
0
 
LVL 5

Accepted Solution

by:
Seth_Bienek earned 2000 total points
ID: 10687905
WS,

I think that what you are trying to do is set a client (server-side) variable using javascript (clientside).

The two easiest approaches to doing this are to either use javascript to forward the user to the next page with a URL param, where the value can be saved as a client variable:
<cfinput type="radio" name="SelectedDepartment" value= "#CountDepartmentStatus.DepartmentCode#" onclick="location.replace('#cgi.script_name#?DepartmentCode=#CountDepartmentStatus.DepartmentCode#');">
As a side note - this onclick event can be used with many different element types, not just form elements.  You can use it in a hyperlink, image, etc.

The other easy approach would be to set a cookie using javascript - then you can access the cookie from later pages using <cfcookie>, or use <cfcookie> to read the value in and save it as a client variable. Just remember that cookie values are stored as text files on the client machine, so you wouldn
t want to use this approach for saving sensitive information.

<cfinput type="radio" name="SelectedDepartment" value= "#CountDepartmentStatus.DepartmentCode#" onclick="SetCookie('DepartmentCode', '#CountDepartmentStatus.DepartmentCode#', 1);">
You'll have to add the SetCookie function do your document within the <head> tags for this approach:
http://www.javascripter.net/faq/settinga.htm

I hope this will give you some ideas for coming up with a solution.  Let us know if we are still not understanding the problem correctly.

Regards,

Seth
0
 

Author Comment

by:Waterstone
ID: 10689963


Seth,

It looks like cookies will be the best solution for this problem.  Do you know of any examples of using cfcookie to read a cookie?

Thanks,
Stece
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10691223
Cookies are not the best solution, for variables that you want to store CLIENT. is the best storage, as it is on your side. The cookie should only store cfid and cftoken which reveals nothing important.

But good luck anyway.
0
 

Author Comment

by:Waterstone
ID: 10691412
I agree that cookies are not ideal, but they allow me to pass a simple variable to the next form no matter what that form is.  It's a solution for a small percentage of the users and the value get's passed to a Client variable as soon as that next form loads.  If there was a way to do a cfset from a radio button it would be ideal, but I'll have to settle for less-than-ideal but functional, unless you know of a better way.

Thanks again for you input.

WS
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 10691562
The way you are setting a cookie will be the same as I suggested to set a client variable.
You should use client variables for settings you like to store for a long period of time ( but not permenant) you should use session variables for variables that exists only throughout the users session.
0
 

Author Comment

by:Waterstone
ID: 10692155


Well, it doesn't seem to be the same to me because setting the client variable seems to require that I use the form's submit button to call the other form.  Is this accurate or am I missing something?
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question