php - javascript/jquery get value of newly checked checkbox -
the following code
<input type="checkbox" id="checkbox" value="brand.php?brand=bmw" name="bmw" <?php echo $checked; ?> > bmw</li> <input type="checkbox" id="checkbox" value="brand.php?brand=toyota" name="toyota"> toyota</li> <input type="checkbox" id="checkbox" value="brand.php?brand=farari" name="farari" checked > farari</li> <input type="checkbox" id="checkbox" value="brand.php?brand=nissan" name="nissan" checked > nissan</li>
my javascript/jquery script is
<script> $(document).ready(function() { var ckbox = $('#checkbox'); var url = ''; console.log(url); $('input').on('click', function() { if(ckbox.is(':checked')) { var url = $(':checked').val(); console.log(url); window.location = url; } }); });
i want page go newly checked checkbox.how make happen?
id
should unique value in whole document. change html have unique id's each checkbox , modify jquery selector based on class or input type.
check below example.
$(document).ready(function() { $('.chkbox').on('change', function() { if ($(this).is(':checked')) { var url = $(this).val(); console.log(url); window.location = url; } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" id="checkbox1" class="chkbox" value="brand.php?brand=bmw" name="bmw"> bmw</li> <input type="checkbox" id="checkbox2" class="chkbox" value="brand.php?brand=toyota" name="toyota"> toyota</li> <input type="checkbox" id="checkbox3" class="chkbox" value="brand.php?brand=farari" name="farari" checked> farari</li> <input type="checkbox" id="checkbox4" class="chkbox" value="brand.php?brand=nissan" name="nissan" checked> nissan</li>
Comments
Post a Comment