I want to enable a input field which is for picking date of payment only if a payment checkbox is checked! clicking on the checkbox triggers a confirmation question for payment and if confirmed the checkbox is checked and the input box will be editable!
here is the code that is not working:
<script type="text/javascript">
$(document).ready(function(){
$("#talk").click(function(){
return confirm("Did you pay the tax?");
var isChecked = $('#talk').is(':checked');
if(isChecked==true)
{
$("#paydate").html('<input type="text" id="name" placeholder="Enter the Date!" />');
}
});
});
</script>
<div id="paydate">
<input type="checkbox" id="talk" />
<input type="text" id="name" readonly />
</div>
Thank you for helping!
no need to recreate your element.
just remove the
readonlyattribute:to lock the checkbox, as you commented, add
$(this).prop('disabled',true)after$('#name').removeAttr('readonly')