user7923788
user7923788

Reputation:

Using Jquery to find two input values for 1 checkbox selection?

I need to retrieve two values, "price and weight" , from 1 checkbox. I am using Jquery Mobile CSS for this.

I simplified the code down and wrote out as much as I could. I don't know how to approach this.

I need the outputs in two separate divs after the box is clicked. I am going to use the results to pass to to simplecartJS.

MY CODE

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TEST LIST</title>
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="simpleCart.js"></script>
</head>
<body>
<fieldset id="" class="" style="margin-top: 0px;font-variant: small-caps;letter-spacing: 2px;" data-role="controlgroup">

    <input class="weight1" type="hidden" value="2.0" >
    <input class="price1" type="radio" name="radio-choice-v-2" id="radio-choice-v-2a" value="20.00" checked="checked">
    <label class="price_weight_lable1" style="display: flex;" for="radio-choice-v-2a">
        <div style="flex:2;">2.0 grams</div>
        <div style="flex:1;text-align: center;">$22.00</div>
    </label>


    <input class="weight2" type="hidden" value="3.5" >
    <input class="price2" type="radio" name="radio-choice-v-2" id="radio-choice-v-2b" value="45.00">
    <label class="price_weight_lable2" style="display: flex;" for="radio-choice-v-2b">
        <div style="flex:2;">3.5 grams</div>
        <div style="flex:1;text-align: center;">$45.00</div>
    </label>


   <input class="weight3" type="hidden" value="7.0" >
    <input class="price3" type="radio" name="radio-choice-v-2" id="radio-choice-v-2c" value="90.00">
    <label class="price_weight_lable3" style="display: flex;" for="radio-choice-v-2c">
        <div style="flex:2;">7.0 grams</div>
        <div style="flex:1;text-align: center;">$90.00</div>
  </label>  
</fieldset>

    <script>
     var price_results;
     var weight_results;

        $("????").click(function(){
        ????            
});

        $(".price_results").html( price_results );
        $(".weight_results").html( weight_results );
    </script>




<div class="simpleCart_shelfItem">


    <div class="item_price"> <!-- simplecart div -->    
        <div class="price_results"></div> <!-- price function result? -->                          
    </div>

     <div class="item_weight"> <!-- simplecart div -->   
        <div class="weight_results"></div>   <!-- weight function result? -->                        
    </div>


</div>

</body>
</html>

copy and paste.

Here is my page www.aarontomlinson.com

Thanks!!!

Upvotes: 0

Views: 50

Answers (1)

Kresimir Pendic
Kresimir Pendic

Reputation: 3614

try this,, that should work for you,,

$('input[type=radio]').on( 'change', function(el){
  $( '.price_results' ).text( $(this).parent().prev().val() );
  $( '.weight_results' ).text( $(this).val() );
});
<link href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


<fieldset id="" class="" style="margin-top: 0px;font-variant: small-caps;letter-spacing: 2px;" data-role="controlgroup">

    <input class="weight1" type="hidden" value="2.0" >
    <input class="price1" type="radio" name="radio-choice-v-2" id="radio-choice-v-2a" value="20.00" checked="checked">
    <label class="price_weight_lable1" style="display: flex;" for="radio-choice-v-2a">
        <div style="flex:2;">2.0 grams</div>
        <div style="flex:1;text-align: center;">$22.00</div>
    </label>


    <input class="weight2" type="hidden" value="3.5" >
    <input class="price2" type="radio" name="radio-choice-v-2" id="radio-choice-v-2b" value="45.00">
    <label class="price_weight_lable2" style="display: flex;" for="radio-choice-v-2b">
        <div style="flex:2;">3.5 grams</div>
        <div style="flex:1;text-align: center;">$45.00</div>
    </label>


   <input class="weight3" type="hidden" value="7.0" >
    <input class="price3" type="radio" name="radio-choice-v-2" id="radio-choice-v-2c" value="90.00">
    <label class="price_weight_lable3" style="display: flex;" for="radio-choice-v-2c">
        <div style="flex:2;">7.0 grams</div>
        <div style="flex:1;text-align: center;">$90.00</div>
  </label>  
</fieldset>


<div class="simpleCart_shelfItem">


    <div class="item_price"> <!-- simplecart div -->    
        <div class="price_results"></div> <!-- price function result? -->                          
    </div>

     <div class="item_weight"> <!-- simplecart div -->   
        <div class="weight_results"></div>   <!-- weight function result? -->                        
    </div>


</div>

Upvotes: 0

Related Questions