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 26 July 2002, 10:04 AM
  #1  
AdrianFRST
Scooby Regular
Thread Starter
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
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!
Old 26 July 2002, 10:05 AM
  #2  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

The NOT operator in JS is !

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

Old 26 July 2002, 10:26 AM
  #3  
AdrianFRST
Scooby Regular
Thread Starter
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
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!
Old 26 July 2002, 11:00 AM
  #4  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
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.
Old 26 July 2002, 11:01 AM
  #5  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

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

Thanks, I'll have a play about with those later.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
the shreksta
General Technical
27
02 October 2015 03:20 PM
Ganz1983
Subaru
5
02 October 2015 09:22 AM
thunder8
General Technical
0
01 October 2015 09:13 PM
shorty87
Other Marques
0
25 September 2015 08:52 PM



Quick Reply: JavaScript - testing for a checked checkbox?



All times are GMT +1. The time now is 03:55 AM.