Binding to non-standard Attributes

ColdFusion rocks, let me just start with that :)

Alright, now that we have that out of the way, I had an issue where I needed to bind a text field to a select menu, but not to the value attribute of that menu. I needed a bunch of other details from that select, and I wanted to prevent a bunch of unnecessary back and forth with the server. So I turned to ColdFusion's binding attributes.

Take the following code:

<cfform name="subscriptionSelection">
   <cfselect name="CostID">
      <option amount="30" description="This is product 1 yo!" value="1">My Product</option>
      <option amount="50" description="This is product 2 yo!" value="2">My Product Two</option>
   </cfselect><br />
   <cfinput type="text" name="cost" bind="{subscriptionSelection:CostID.amount}" />
   <cfinput type="text" name="description" bind="{subscriptionSelection:CostID.description}" />
</cfform>

And it works like a charm. When the select is changed, both the cost and description fields will pick up the custom attributes I added to the select. Now to be 100% standards compliant I'd need to build a custom DTD to include my custom attributes, but 99.9% of the time that's not necessary. Just take a moment and revel in the ease of using ColdFusion to do your dynamic bidding.

0 responses to “Binding to non-standard Attributes”

Leave a Reply

Leave this field empty:

Powered by Mango Blog.