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.
cmckoyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
azadisaryevConnect With a Mentor Commented:
>> 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.

Azadi

<!--- 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="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<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
}
</script>
<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">
</form>

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

<cfif val(url.id) 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(url.id)#">
  </cfquery>
</cfif>

Open in new window

0
 
azadisaryevCommented:
Ray's recent post deals with exactly this:

http://www.coldfusionjedi.com/index.cfm/2010/3/30/Quick-example--updating-stuff-with-CFSLIDER

read the comments as well.

Azadi
0
 
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.
0
 
cmckoyAuthor Commented:
Excellent... thanks... I know many people will be thankful!
0
All Courses

From novice to tech pro — start learning today.