php - I have a checkbox that correlates directly to an input amount. If there is an input amount the checkbox has to be checked before post -
i've created function standard checkbox in php, it's called cbox standard input box called inp.
<tr><td><?php cbox('charge_cc'); ?> charge cc? amount $ <?php inp('charge_amt'); ?></td></tr> if there amount entered 'charge_amt' inp field checkbox needs checked before post/submit.
if no amount has been entered input field not need check box , can proceed fill out rest of form , submit. i'm uncertain on how accomplish because think php functions cbox , inp breaking jquery/javascript.
as of i've tried few variations:
<script type="text/javascript"> function validate(){ if (document.getelementbyid('charge_cc').checked){ alert("checked") ; }else{ alert("you didn't check it! let me check you.") } } </script> no avail, appreciated.
<td><input type="hidden" name="charge_cc" value="0" class="charge_cc"> <input type="checkbox" id="charge_cc" name="charge_cc" value="1" class="charge_cc"> charge cc? amount $ <input type="text" id="charge_amt" name="charge_amt" value="" size="8" maxlength="6"></td>
if need check/uncheck checkbox depending on entry in charge_amt text-input, i'd suggest:
$('#charge_amt').keyup(function(){ var = this; $('#charge_cc').prop('checked', function(){ return that.value.length; }); }); if want prevent user un-checking checkbox once there's value in text-input:
$('#charge_amt').keyup(function () { var test = this.value.length; $('#charge_cc').prop({ 'checked': test, 'disabled': test }); });
Comments
Post a Comment