0

In my current program I am trying to pull the data-price value and the value=" " as well. I know I need to somehow implement the

$(this).attr( )

but it isn't pulling the right information. I am trying to declare a value called id for the seat name and value price for seat cost whenever the checkbox is selected. Any suggestions?

https://jsfiddle.net/pnuqyyqh/5/

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
narue1992
  • 1,143
  • 1
  • 14
  • 40

2 Answers2

1

The following code will get you started:

$(function() {
    $("input[type=checkbox]").on("change",function(){
        getPropChecked = $(this).prop("checked");
        if(getPropChecked)
        {
            getId = $(this).prop("id");
            getValue = $(this).attr("value");
            getDataPrice = $(this).attr("data-price");
            alert("getId: " + getId + 
              " getValue: " + getValue +  
              " getDataPrice:" + getDataPrice);
        }
    })
})

Please refer to this stack overflow post

Community
  • 1
  • 1
0

You obtain a data attribute with $(this).data('price'); and its value with $(this).val()

André Silva
  • 1,110
  • 8
  • 24
  • Weirdest thing. When I use $(this).val() I get a `Cannot read property 'toLowerCase' of undefined' from my meta: ` ` ?? – narue1992 May 13 '15 at 13:17
  • 1
    It's not weird, `$(this)` references the checkbox input on the click callback function. Your update function does not know what `$(this)` means. I'm going to edit your jsFiddle. – André Silva May 13 '15 at 13:31