jquery - Need helping passing javascript variable through hidden form input -
okay, have javascript calculate dynamic price html form. code follows:
jquery("input[name='amount']").change(function() { if (isnan(parsefloat(this.value)) || !isfinite(this.value)) { jquery(this).val(''); return false; } var calc = parsefloat(this.value) * 0.95; jquery(this).parents("form").find("input[name='price']").val(calc); });
this, form input:
<input class="irrelevant typeahead" type="text" placeholder="amount" name="amount"/>
the javascript takes value, calculates price, , want fill this:
<input type="hidden" name="price" value=""/>
i believe javascript correct. need price make work?
edit 2: resolved it! guys. issue in location of javascript!
please try below code snippet. code works @ side.
<!doctype html> <html> <head> <title>test</title> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> </head> <body> <form> <input class="irrelevant typeahead" type="text" placeholder="amount" name="amount" /> <input type="hidden" name="price" value="" /> <script type="text/javascript"> jquery("input[name='amount']").change(function () { if (isnan(parsefloat(this.value)) || !isfinite(this.value)) { jquery(this).val(''); return false; } var calc = parsefloat(this.value) * 0.95; jquery(this).parents("form").find("input[name='price']").val(calc); }); </script> </form> </body> </html>
Comments
Post a Comment