I want to change my checkbox required default message.
I am trying with this code but if I check my checkbox then it still shows required message.
my code
<input required type="checkbox" name="rcheck2"
oninvalid="this.setCustomValidity('check plz')" oninput="setCustomValidity('')" />
/
I want to change my checkbox required default message.
I am trying with this code but if I check my checkbox then it still shows required message.
my code
<input required type="checkbox" name="rcheck2"
oninvalid="this.setCustomValidity('check plz')" oninput="setCustomValidity('')" />
https://jsfiddle/6ekk9upz/
Share Improve this question edited Aug 9, 2016 at 14:02 testset asked Aug 9, 2016 at 13:57 testsettestset 411 gold badge1 silver badge3 bronze badges 3- Please post a functional example that illustrates your problem on jsFiddle. – palaѕн Commented Aug 9, 2016 at 13:59
- Show us all the code. We are not able to help you when we don't see what you are doing ;) BTW Why are you calling JS "this." object in html as i see? – Stefan Stefko Commented Aug 9, 2016 at 14:00
- please check jsfiddle/6ekk9upz @palaѕн – testset Commented Aug 9, 2016 at 14:02
2 Answers
Reset to default 16checkbox inputs don't have the oninput
event, they have the onchange
event.
Check this:
<form action="" name="formReg" id="formReg" method="post" class="formReg">
<div class="checkTxt">
<input required type="checkbox" name="rcheck1" oninvalid="this.setCustomValidity('check plz')" onchange="this.setCustomValidity('')"/>
</div>
<div class="checkTxt">
<input required type="checkbox" name="rcheck2" oninvalid="this.setCustomValidity('check plz')" onchange="this.setCustomValidity('')"/>
</div>
<div class="checkTxt">
<input required type="checkbox" name="rcheck3" oninvalid="this.setCustomValidity('check plz')" onchange="this.setCustomValidity('')"/>
</div>
<input type="submit" name="btnReg" value="Submite"/>
</form>
simply try this code , this is for typescript (react) but you can do as you like
onInvalid={(e) => {
const target = e.target as HTMLInputElement
target.setCustomValidity("Please tick this box to proceed.")
}}