Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #34740

Re: What's wrong with the following uncheck checkbox code?

Newsgroups comp.lang.javascript
Subject Re: What's wrong with the following uncheck checkbox code?
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <9df167cc-f509-4d11-bb6b-83b34cd3d3e1@googlegroups.com>
Date 2018-02-23 13:22 +0100
Message-ID <XnsA89288033BD95eejj99@194.109.6.166> (permalink)

Show all headers | View raw


justaguy <lichunshen84@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)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What's wrong with the following uncheck checkbox code? justaguy <lichunshen84@gmail.com> - 2018-02-23 04:00 -0800
  Re: What's wrong with the following uncheck checkbox code? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-02-23 13:22 +0100
  Re: What's wrong with the following uncheck checkbox code? justaguy <lichunshen84@gmail.com> - 2018-02-23 05:45 -0800

csiph-web