Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-03-2008, 02:19 PM   PM User | #1
Schteeve
New Coder

 
Join Date: Jun 2007
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
Schteeve is an unknown quantity at this point
Dynamic check box limit

I am using the following code to limit the number of checkboxes a user can check:

Code:
var MAX_ALLOWED=5;
var clickedData=new Array(false,false,false,false);
function itemsClicked(){var i=0;for(var j=0;j<clickedData.length;j++)i+=clickedData[j]?1:0;return(i);}
function itemClicked(_v)
{
  var ALLOW_THIS=true;
  var x=itemsClicked();
  if (x>=MAX_ALLOWED && !clickedData[_v])
  {
    ALLOW_THIS=false;
  }
  else
  {
    clickedData[_v]=clickedData[_v]?false:true;
	eval("document.create_exhib.r"+_v+".clicked=false;");
  }
  <!--document.showit.s1.value=x; /* comment out */-->
  return (ALLOW_THIS); /* kill the event handler */
}
The problem comes when i use this code on dynamically a populated form:
eg. previously checked boxes are marked
Code:
checked="checked"
when they match an entry in the relevant database.

The script cannot seem to calculate the limit with this dynamic data thrown in.

Has anyone else experienced a similar problem or could anyone recommend a more suitable peice of code.

Many Thanks!
__________________
You think anybody wants a roundhouse kick to the face while I'm wearing these bad boys? Forget about it.
<!------------o\/o-----------?>
Schteeve is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:08 AM.


Advertisement
Log in to turn off these ads.