jquery with variable php -
i have code php
............................ .............................. ................. <input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" stock=" <?php if ($option_value['subtract']) { ?> <?php if ($option_value['quantity'] >= 3) { ?> <?php echo $text_in_stock; ?> <?php } ?> <?php if ($option_value['quantity'] < 3 && $option_value['quantity'] > 0) { ?> <?php echo $option_value['quantity']; ?> <?php echo $text_pcs_only; ?> <?php } ?> <?php if ($option_value['quantity'] <= 0) { ?> <?php echo $text_out_of_stock; ?> <?php } ?> <?php } ?> " value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" onchange="recalculateprice();" /> <div class="pippo"> ................. ....... </div>
then have script
<script type="text/javascript"> function recalculateprice() { var stock = $('#style_stock').attr('stock'); $('input[type=radio]:checked').each(function() { $('.pippo').hide(); if ($(this).attr('stock') != '<?php echo $text_out_of_stock; ?>') { $('.pippo').show() stock = $(this).attr('stock'); } });
i need hide div pippo when check option stock = . attr stock in option radio has if .... have insert in row ?
if ($(this).attr('stock') != '<?php echo $text_out_of_stock; ?>') {
i can't tell problem here few important notes:- first in php
try calculate stock value outside input tag stock attribute & echo final value , remove spaces.
try use "else if" instead of stacking "if" commands , making ambiguity in value (its easier)
second in javascript
the code have written show ".pippo" div in case if there @ least on radio button attribute
stock != out_of_stock
need make sure testing changed radio.the value of
$(this).attr('stock')
in case use line directly undefined u didn't define .finally calling
onchange
attribute make problems in page loading , may give error of undefined function
so instead prefer long using jquery
attach events through jquery
here full sample of may can use
html
<div class="pippo"> ................. ....... </div> <input type="radio" stock="...." name="opt"> <input type="radio" checked="checked" stock="10" name="opt"> <div id="style_stock" stock="10">stock = 10</div>
javascript
function recalculateprice(x) { if ($(x).attr('stock') != '....') { $('.pippo').show(); //put code want }else{ $('.pippo').hide(); //put code want } } $("input[type=radio]").change(function(){ recalculateprice(this); });
Comments
Post a Comment