Making CheckBox Selected

This is a discussion on "Making CheckBox Selected" within the JavaScript Forum section. This forum, and the thread "Making CheckBox Selected are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Sep 10th, 2007, 20:10
New Member
Join Date: Sep 2007
Location: USA
Age: 32
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Smile Making CheckBox Selected

Hi,

I'm having the following javascript code,after all the checkboxes are unslected,I'll display the alert to user saying that "Atleast one must be selected",but the checkbox is becoming unselected after throwing Alert,how to make check box to remain selected after throwing this alert.
I'm calling this java script function in the onClick event of checkbox.

var checkSelected = false;
for (i = 0; i < planForm.locationOptions.length; i++) {
if (planForm.locationOptions[i].checked) {
checkSelected = true
document.planForm.action='refreshPlanView.do';docu ment.planForm.submit();
document.getElementById("refreshing").style.displa y="block";
}
}
if (!checkSelected) {
alert("At least ONE Location must be selected!");
return false;
}
return true;
}

Please advise..

Thanks,
Kumar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Sep 10th, 2007, 20:36
alexgeek's Avatar
Moderator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,814
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Re: Making CheckBox Selected

uh wouldn't you have the alert, then on the next line code to make the checkbox selected?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Sep 10th, 2007, 20:57
New Member
Join Date: Sep 2007
Location: USA
Age: 32
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making CheckBox Selected

I didn't exactly understand the question/answer what you are trying to say?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 10th, 2007, 21:08
alexgeek's Avatar
Moderator
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,814
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Re: Making CheckBox Selected

I'm not too good with explaining lately.
Sorry
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Sep 11th, 2007, 05:20
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Making CheckBox Selected

If I'm understanding correctly, the alert is being thrown because no checkboxes are selected so this means they were all unselected before the alert anyway?

I think you could try

passing the checkbox to the function so declare the function something like

function checkboxcheck(obj)

then in your checkboxes onclick="checkboxcheck(this)"

and finally

if (!checkSelected) {
alert("At least ONE Location must be selected!");
obj.checked = true;
return false;
}


This should keep the last checkbox checked at all times.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
htmlp

Thread Tools

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Selected radio button value Pugger JavaScript Forum 8 Nov 3rd, 2007 14:16
Required text field if Other selected from a list redlevel JavaScript Forum 3 May 16th, 2007 16:32
How to view selected field only? awiezzz Classic ASP 1 May 13th, 2007 17:12
Guide me how to show previously selected item in listbox frmsasp ASP.NET Forum 1 Jan 26th, 2006 15:37
How to get value of selected dynamic checkboxes? frmsasp ASP.NET Forum 1 Nov 3rd, 2005 13:59


All times are GMT. The time now is 01:06.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved