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.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 10th, 2007, 19: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
Reply With Quote

  #2 (permalink)  
Old Sep 10th, 2007, 19:36
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Making CheckBox Selected

uh wouldn't you have the alert, then on the next line code to make the checkbox selected?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Sep 10th, 2007, 19: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?
Reply With Quote
  #4 (permalink)  
Old Sep 10th, 2007, 20:08
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Making CheckBox Selected

I'm not too good with explaining lately.
Sorry
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #5 (permalink)  
Old Sep 11th, 2007, 04: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)
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 12:16
Required text field if Other selected from a list redlevel JavaScript Forum 3 May 16th, 2007 15:32
How to view selected field only? awiezzz Classic ASP 1 May 13th, 2007 16:12
Guide me how to show previously selected item in listbox frmsasp ASP.NET Forum 1 Jan 26th, 2006 14:37
How to get value of selected dynamic checkboxes? frmsasp ASP.NET Forum 1 Nov 3rd, 2005 12:59


All times are GMT. The time now is 10:43.


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43