Since you have a very specific use case, you're probably better off just
writing custom logic to accomplish this task.
However, one way you could "hack" this solution is to define a custom
jQuery.fn.getValue function:

jQuery.fn.getValue = function (){
  return this.attr("some_str");
}

If the calc plug-in finds a jQuery method called "getValue" it'll use that
function to retrieve it's value instead of the val method. So you can just
write a getValue method that grabs the value from the correct location.

Just be aware that the getValue() method will be used for all the methods in
the calc plugin for retrieving the value.

-Dan

On Wed, Jul 15, 2009 at 8:57 AM, introvert <aljaz.faj...@gmail.com> wrote:

>
> Hello,
>
> I need some help on jquery.calculation plugin modification (I want to
> change it so that it would also read the attributes of elements if a
> string is passed as an attribute name).
>
> I want to change the .calc function so that I could optinally pass a
> string with each jquery object which are passed as an array of
> objects:
>
> ("[id^=total_item]").calc(
>        "qty * price",
>        // define the variables used in the equation, these can be a jQuery
> object
>        {
>                qty: $("input[name^=qty_item_]"),
>                price: $("[id^=price_item_]")
>        },
>        function (s){
>                return "$" + s.toFixed(2);
>        },
>        function ($this){
>        }
> );
>
> I want to be able to specify a string for each row in an array (qty,
> price) (as an array).
>
> Maybe something like:
>                qty: $("input[name^=qty_item_]")["some_str"],
>                price: $("[id^=price_item_]")
>
>
> I'm unsure how should I change the syntax and retrive the value inside
> the calc function (the second argument is called vars):
>
> for( var k in vars ){
>        // replace the keys in the expression
>        expr = expr.replace( (new RegExp("(" + k + ")", "g")), "_.$1");
>        if( !!vars[k] && !!vars[k].jquery ){
>                parsedVars[k] = vars[k].parseNumber();
>        } else {
>                parsedVars[k] = vars[k];
>        }
> }
>
> Many thanks in advance!
>

Reply via email to