Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

JavaScript - testing for a checked checkbox?

Thread Tools
 
Search this Thread
 
Old Jul 26, 2002 | 10:04 AM
  #1  
AdrianFRST's Avatar
AdrianFRST
Thread Starter
Scooby Regular
 
Joined: Oct 2000
Posts: 368
Likes: 0
Question

I have a form which cannot be submitted until the user checks an 'agree' box:

<INPUT id="checkAgree" type="checkbox" name="checkAgree" value="agree">

In my JS validation I have:

if (document.frmProcessreg.checkAgree.checked)
{
alert("Please confirm you have read and agree to the terms and conditions.");
}

Obviously this is doing the opposite of what I want, bringing up the alert if the box is checked, not unchecked. I've tried "if (document.frmProcessreg.checkAgree.value != 'agree') but that doesn't want to work. Neither does "if not (document... etc".

Any suggestions?

Thanks!
Reply
Old Jul 26, 2002 | 10:05 AM
  #2  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

The NOT operator in JS is !

so
if (!(doc....))

Reply
Old Jul 26, 2002 | 10:26 AM
  #3  
AdrianFRST's Avatar
AdrianFRST
Thread Starter
Scooby Regular
 
Joined: Oct 2000
Posts: 368
Likes: 0
Post

Sorted thanks!

Sooo simple as well. Clearly too easy for you so....

I have a registration form here:

http://www.crewise.com/earnwise/registration.asp

At the section for Qualifications / Skills there are three colums and three rows, to enable three qualifications to be entered.

What I need to do is initially show one row, with a button to add more, so that the user can enter as many or as few qualifications as they need to.

I've done something like this before, dynamically building tables, but that was with code a collegue wrote.

What I've tried so far is this:

----------------------
var theHTML
theHTML = "<TR><TD>test</TD></TR>"

function addRow()
{
theHTML = theHTML + "<TR><TD>test</TD></TR>"
}
----------------------

then a link to run addRow();

As I expected, this doesn't update the page and reloading it will reset all the fields on the form. I think it may be done with a span or a div container.

Should have took a copy of the code when I had the chance!

Thanks!
Reply
Old Jul 26, 2002 | 11:00 AM
  #4  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

Overkill for what you want, but you could see what's being done in this example and take it from there: http://www.mattkruse.com/javascript/...mentation.html

Just another point: you should check your checked flag on the server side too, as people can and do turn off Javascript, or create their own submit page, or ... Never rely on client side authentication.
Reply
Old Jul 26, 2002 | 11:01 AM
  #5  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

...or look at this too:
http://javascript.internet.com/forms/dynamic-table.html
Reply
Old Jul 26, 2002 | 12:10 PM
  #6  
AdrianFRST's Avatar
AdrianFRST
Thread Starter
Scooby Regular
 
Joined: Oct 2000
Posts: 368
Likes: 0
Post

Thanks, I'll have a play about with those later.
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
the shreksta
General Technical
27
Oct 2, 2015 03:20 PM
Ganz1983
Subaru
5
Oct 2, 2015 09:22 AM
thunder8
General Technical
0
Oct 1, 2015 09:13 PM
shorty87
Other Marques
0
Sep 25, 2015 08:52 PM




All times are GMT +1. The time now is 01:31 PM.