Jump to content


Adding Custom Function To An Object

jquery object

  • Please log in to reply
2 replies to this topic

#1 akphidelt2007


    Advanced Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 November 2012 - 12:20 PM

Ok, I really should know this by now and I'm in a time crunch so I thought I might just ask to see if someone can point me in the right direction. So I build a table class in jquery. What I want now is to be able to handle custom functions that come about for the individuals tables I create. What I do now is have a customChange function and just use switch() to find the keyword and then run the function. But this is mighty inefficient and I have to constantly go in to the object and add the single custom instance.

So for example, say on one table when the Qty is changed I want the Cost column to autocalculate and trigger a warning if the cost is above a certain value.

I load up my javascript like this...

$(function() {
    var tbl = new Tablev2('beta');

How can I type up the function within the $this->ajax->loadScript function so I do not have to actually manipulate the object but still use the variables within the object? The way I do it now is through the tbl.customChangeEvent() and then I just write the function in the class itself. I want to be able to write the function on the script that is creating the table.

Any help will be greatly appreciated. Thanks

#2 akphidelt2007


    Advanced Member

  • Members
  • PipPipPip
  • 154 posts

Posted 16 November 2012 - 12:53 PM

So I'm still trying to put the pieces together. Here is more of a clear picture of what I want.

$(function() {
var tbl = new Tablev2('beta');

//right here, I want to add the ability to calculate the cost based on the unit_cost and qty
//I'd like to do something like this

tbl.addFunctionSomeHow(function() {
$('#qty').blur(function() {

This is literally just an example of what I want to do. I want to be able to have access to this so I can manipulate the table via the custom function. Do not worry about the actual validity of the function above. I just types it up for a broad example of what I'm trying to accomplish.

Thanks again.

Edited by akphidelt2007, 16 November 2012 - 12:54 PM.

#3 Adam


    Advanced Member

  • Gurus
  • 5,709 posts
  • LocationSheffield / UK

Posted 17 November 2012 - 08:27 PM

Hmm you seem to be talking about "custom change events" like we know what they are?

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime