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.

1 Answer 1

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');
Sign up to request clarification or add additional context in comments.

5 Comments

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
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.
see stackoverflow.com/questions/66420/… for how to debug javascript in chrome
again - perfect - that's what it returns. Now I think my other stuff is off a bit. Stand by for more code.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.