Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Sponsored Links

Discuss "checkbox validation" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old June 18th, 2008, 03:14 PM
Barn Frequenter
 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default checkbox validation

719-572-9400
719-638-3545


hi,

I have a group of checkboxes like this
Code:
<input type="checkbox" name="chk12" id="chk12" value="Yes">Quote 12
<input type="checkbox" name="chk11" id="chk11" value="Yes">Quote 11
<input type="checkbox" name="chk10" id="chk10" value="Yes">Quote 10
<input type="checkbox" name="chk9" id="chk9" value="Yes">Quote 9
<input type="checkbox" name="chk8" id="chk8" value="Yes">Other

<input type="textbox" name="chk8othertext" id="chk8othertext" value="">
If the user doesnt select one of them then i want to fire an alert

if the user selects Other checkbox and doesnt enter a value in the other textbox then fire an alert

here is my code

Code:
if (document.frm1.chk12.checked == false && document.frm1.chk11.checked == false && document.frm1.chk10.checked == false && document.frm1.chk9.checked == false && document.frm1.chk8.checked == false )
		{
		alert ('You didn\'t choose any of the checkboxes!');
		return false;
		}
	else
		{
		return true;
		}

If(document.frm1.chk8.checked ==true)
	{
		if(document.frm1.chk8othertext.value =="")
			{
			alert("enter a value");
			}
	}
but the code is not working

any idea

todd
Reply With Quote
Sponsored Links
  #2  
Old June 18th, 2008, 03:24 PM
Wolffy's Avatar
Slaprentice of Wolves
 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

You never get to your second IF statement. Remove the else clause of hte first IF.
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
The Following User Says Thank You to Wolffy For This Useful Post:
richyrich (June 19th, 2008)
  #3  
Old June 18th, 2008, 03:24 PM
mehere's Avatar
Super Sarcasm Mistress
 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 147
Thanks: 11
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

what do you mean not working? are you getting an error message?
__________________
Quote of the Month:
Quality: The race for quality has no finish line- so technically, it's more like a death march.

Questions to Ponder:
What do you do when you see an endangered animal eating an endangered plant?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
Reply With Quote
  #4  
Old June 18th, 2008, 07:22 PM
don94403's Avatar
Moderator
 
Join Date: Mar 2008
Location: San Mateo, CA, USA
Posts: 63
Thanks: 3
Thanked 8 Times in 8 Posts
Blog Entries: 2
Rep Power: 1
don94403 is on a distinguished road

Awards Showcase
Microsoft Access PHP 
Total Awards: 2

Default

Assuming that your code is in some Event Procedure, Wolffy is right. The way you have it, the first If statement either returns True or False, but in either case it returns, which means bye-bye, it's done.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display problem checkbox todd2006 JavaScript Programming 4 May 30th, 2008 03:58 PM
[ASP.Net/VB.Net] Programmatically Add Item to Validation Summary jmurrayhead Code Samples 0 March 20th, 2008 09:41 AM


All times are GMT -4. The time now is 03:48 PM.



Content Relevant URLs by vBSEO 3.2.0