check box from hell

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

check box from hell

Post by deeessay »

Hi there, my problem is not php-related but javascript. I posted it here anyway hoping that you all might help me with it.


I have a 7 checkboxes, right, named cb1 thru cb7, and I added a code in javascript that sends an alert message if it detected that all checkboxes are not ticked.

here's the code:
==========================================================================================
if (document.frm.cb1.checked == false && document.frm.cb2.checked == false && document.frm.cb3.checked == false && document.frm.cb4.checked == false && document.frm.cb5.checked == false && document.frm.cb6.checked == false && document.frm.cb7.checked == false)
{
alert ("at least one checkbox must be ticked.");
return false;
}
===========================================================================================

The problem is this:

One of the checkbox is ticked but disabled... how can I tell javascript that a checkbox is ticked only disabled?

Javascript seems to treat disabled boxes as if they are unticked.


Thanks in advance for any help you people can give :)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: check box from hell

Post by jayshields »

http://www.google.com/search?q=javascri ... d+checkbox The first result tells you everything you need to know...
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Re: check box from hell

Post by deeessay »

Thank you for your help, Jay!
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Re: check box from hell

Post by deeessay »

Hi again, the script can now detect if a checkbox is disabled but when a checkbox is disabled and ticked, it cannot detect that the checkbox is ticked.

I added this code:

if (document.frm.cb1.disabled == false && document.frm.cb1.checked == true)
{
alert ("disabled but ticked."); return false;
}


I cannot make the condition true. the cb1 checkbox is disabled and checked:

<input type='checkbox' name='cb1' value='1' disabled checked>

Is there anyway of modifying he code such that it can tell the difference between a disabled and unticked checkbox and a disabled but ticked checkbox?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: check box from hell

Post by RobertGonzalez »

deeessay wrote:Hi there, my problem is not php-related but javascript.
PHP - Code is the forum for PHP related questions. Miscellaneous is what we use for other programming language related questions.

Moved to miscellaneous.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: check box from hell

Post by jayshields »

Shouldn't this be in Client Side, not Miscellaneous?

Your if() statement that you added is incorrect for what you want. You are checking if the disabled attribute is false, meaning that it is enabled. So your if() statement is checking for an enabled and checked checkbox, not a disabled and checked checkbox.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: check box from hell

Post by RobertGonzalez »

Client side is design/UI related type things. The questions asked in this thread are programming related so I moved it to Miscellaneous, which is where programming questions that are not PHP related belong.
Post Reply