jquery - using .val not working with variables? -
i using jquery, mmy code supposed have 2 inputs (btn1 , btn2) in html when modified, reflect alter on other input, code:
$(document).ready(function(){ $(document).on('input','.btn1',function(){ var value3 = 1; $(".btn2").val(value3); }); $(document).on('input','.btn2',function(){ $(".btn1").val(6); }); });
when modifying first input, nil changes, when changing 2nd one, show value "6". doing wrong doesn't show variable?
<form action="" method="post" enctype="multipart/form-data"> <h1 class="titu hidden" >quantity 1</h1> <input class="btn1 hidden" type="number" name="cantpag" value="<?php echo $cp; ?>"> <h1 class="titu hidden">quantity 2</h1> <input class="btn2 hidden" type="number" name="cantreinv" value="<?php echo $cr; ?>"> <input class="sbmtbtn hidden" type="submit"> </form>
class="snippet-code-js lang-js prettyprint-override">$(document).ready(function() { $(document).on('input', '.btn1', function() { var value3 = 1; $(".btn2").val(value3); }); $(document).on('input', '.btn2', function() { $(".btn1").val(6); }); });
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <form action="" method="post" enctype="multipart/form-data"> <h1 class="titu hidden">quantity 1</h1> <input class="btn1 hidden" type="number" name="cantpag" value="0"> <h1 class="titu hidden">quantity 2</h1> <input class="btn2 hidden" type="number" name="cantreinv" value="0"> <input class="sbmtbtn hidden" type="submit"> </form>
jquery
No comments:
Post a Comment