Update hidden input value with onclick event from ajax drop down menu

I'm working with MachForm and have this hidden field that I've added:

<input type="hidden" name="element_273_price" value="">

I've integrated an ajax drop down menu that allows for an onclick event to be fired. I'd like the hidden field above to have a value inputted after the onclick event (onclick would tell the hidden field what the item was and price for that item) so that I can then pass it along through the rest of the JavaScript for the updating of the price on screen.

Here's my code for calculating a text box:

        $('#main_body li[data-pricefield="text"]').delegate('input.text','keyup mouseout change', function(e) {
        var temp = $(this).attr("id").split('_');
        var element_id = temp[1];
        var ordered = (document.getElementById("element_" + element_id).value);
        var price = $(this).data('pricedef');

        var price_value = price * ordered;
        price_value = parseFloat(price_value);
        if(isNaN(price_value)){
            price_value = 0;
        }

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

Answers:

Answer

Try to put in your php file:

'onlick' => '$("element_'.$yourelementid.'_price").val("'.$data['price'].'");'

Then you'll have in your javascript to get the value from this hidden input instead of the data-pricedef attribute of your "Quantity" input.

Correct me if I do not understand your problem. I tried to reply from the code you showed in your video.

Answer

If you change the input to

<input type="hidden" id="element_273_price" value="">

You should be able to do

$("#element_273_price").val(price_value);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.