How do I automatically update a database record with cfslider?

I need to use cflsider to display a value from a database and update the value when it is dragged. Any help would be very much appreciated... I can't find any good examples online. Thanks.
Who is Participating?
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.

Ray's recent post deals with exactly this:

read the comments as well.

cmckoyAuthor Commented:
I'm having a hard time converting that example to update a database instead of a local variable. An example would be great.
>> I'm having a hard time converting that example to update a database instead of a local variable. An example would be great.

in its simplest form, you would just replace ray's <cfset session.slider = url.newvalue> in the last code snippet with a <cfquery> to update your db.

if you are up for more complicated stuff, you can call a cfc method that updates your db instead of a .cfm page, either using jquery like ray does in his post, or by using a js proxy created with <cfajaximport> tag...

of course, unless you want to update all records in your db with the new slider value, you will need to pass a unique id of the record to update to your cfm/cfc. you can store the id of record being edited in a hidden field in your form and get it using js (jquery selector or your regular document.getElementById()) and pass it as parameter/attribute to your cfm/cfc that updates the db.

some sample code (based on ray's post) is attached.


<!--- the form page --->
<cfparam name="defaultslidervalue" default="50">
<!--- the above should be replaced with slider current value from your db, whichever way you get that value (presumably some SELECT query) --->
<script type="text/javascript" src=""></script>
function sliderChange(ob, value) {
  var recid = $("#recordID").val();
  $.get("updateslider.cfm",{"id":recid, "newvalue":value});
  // if you need more control over ajax call, use $.ajax() instead.
  //see jquery docs for details
<form ...>
<input type="hidden" name="recordID" id="recordID" value="42" />
<b>Your Coolness:</b>
<cfslider format="html"  min="1" max="100" value="#defaultslidervalue#" name="coolness" onchange="sliderChange" tip="false">

<!--- updateslider.cfm page --->
<cfparam name="" default="">
<cfparam name="url.newvalue" default="">

<cfif val( gt 0 AND isNumeric(url.newvalue) AND round(url.newvalue) is url.newvalue AND url.newvalue gte 1 AND url.newvalue lte 100>
  <cfquery ...>
  UPDATE sometable
  SET somecolumn = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.newvalue#">
  WHERE idcolumn = <cfqueryparam cfsqltype="cf_sql_integer" value="#val(">

Open in new window


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
cmckoyAuthor Commented:
Excellent... thanks... I know many people will be thankful!
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
Web Servers

From novice to tech pro — start learning today.