0

I have an html doc that contains:

        <li id="li_273" data-pricefield="special" data-pricevalue="0" >
        <label class="description" for="element_273">Helium Foil Balloon #1 </label>
            <div>
                <input type="text" class="element text medium" id="element_273" name="element_273" size="30" value="" />
                <input type="hidden" id="element_273_price" name="element_273_price" value="">

            </div> 
       </li>

So then, that area is an ajax drop down menu. From that ajax/php drop down I am able to execute an onclick command - this is what I have:

'onclick' => 'document.getElementById(\'li_273\').data(\'pricevalue\',\'1.00\');',  

It all gets json_encoded and this is the portion that it returns:

"onclick":"document.getElementById('li_273').data('pricevalue','1.00');",

But yet I get an error message when I select something from the ajax menu and onclick:

Uncaught TypeError: Object #<HTMLLIElement> has no method 'data' 

I cannot for the life of me figure this out and all I need it to do is just update a price that is on the page.

UPDATE: here's the rest of the code to try to get it to actually calculate the JavaScript on the page:

        $('#main_body li[data-pricefield="special"]').delegate('onclick','change', function(e) {
        var temp = $(this).attr("id").split('_');
        var element_id = temp[1];

        var pricedef = $(this).data('pricedef');
        if(pricedef == null){
            pricedef = 0;
        }

        $("#li_" + element_id).data("pricevalue",pricedef);
        calculate_total_payment();
           });

What seems to be missing? Because it doesn't update the total on the page.

halfer
  • 19,824
  • 17
  • 99
  • 186
MrTechie
  • 1,797
  • 4
  • 20
  • 36

1 Answers1

3

.data is a jquery function and you are probably trying to call it on a dom object. Make sure you have jQuery loaded on your page and then do:

jQuery('#li_273').data('pricevalue','1.00');
DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
  • that's seemed to have taken care of the error. How can I check it for sure? If I try viewing source it obviously sets the price back to 0. Is there a way I can see it to make sure it's updated? I am using Chrome's Developer tools – MrTechie Dec 21 '12 at 21:29
  • 1
    If your using chrome or firefox load the page, perform your actions that will set the data and then go into the javascript console and type `jQuery('#li_273').data('pricevalue');`. If the console returns `1.00` then you know its working. – DiverseAndRemote.com Dec 21 '12 at 21:32
  • 1
    see http://stackoverflow.com/questions/66420/how-do-you-launch-the-javascript-debugger-in-google-chrome for how to debug javascript in chrome – DiverseAndRemote.com Dec 21 '12 at 21:33
  • again - perfect - that's what it returns. Now I think my other stuff is off a bit. Stand by for more code. – MrTechie Dec 21 '12 at 21:33
  • If you have a different problem you should post another question on stackoverflow and you will get more answers. As for this one you should consider it answered. – DiverseAndRemote.com Dec 21 '12 at 21:36