justaguy <
lichun...@gmail.com> wrote on 23 Feb 2018 in
comp.lang.javascript:
>
> For the following FORM, if for whatever reason the user has already
> checked the checkbox field with id of "sig" but its prior field's value
> is invalid, uncheck this checkbox. See below. However, the uncheck
> function fails. document.getElementById('sig').checked = false;
> Its syntax seems correct. Why? Thanks.
>
> <form>
> enter promo code:
> <input type="text" id="code" name="code" onblur="verify(this)">
> <span id="note" style="color:red"></span>
>
> yes to include signature: <input type="checkbox" id='sig' name='sig'
> value=1>
<input type="checkbox" id='sig' name='sig'>
There should better be no "value=1" in your input checkbox,
if you want it checked by default, use 'checked'.
> <!-- other elements below -->
> ...
> <input type="submit" name='send'>
> </form>
>
> <script>
> var verify = function {
> if (this !== 'whatevercode') {
in input type="text"
'this' cannot be a string by itself,
as it is/points to a DOM-object.
so you could use this.value,
and in the function,
you have to reference this 'this',
not write this 'this'.
onblur = "verify(this);"
var verify = function(t) {
if (t.value !== 'whatevercode')
...
};
or
'use strict';
const verify = (t) => {
if (t.value !== 'whatevercode')
...
};
> // alert the user
> document.getElementById('note').innerHTML = 'Your promo code is
> invalid';
>
> // uncheck signature checkbox field
> document.getElementById('sig').checked = false;
> }
>
> }
> </script>
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)