It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming JavaScript Forum

Javascript Checkbox Validation Require

Javascript Checkbox Validation Require

Postby jamyers79 on Mon Aug 22, 2005 4:37 pm

I currently have 6 options in which a user MUST select 3 choices... no more... no less... I currently have a script in place that doesn't allow you to check more than 3 however you can not check anything and it goes through which is NOT what needs to happen.

Here is my current JS:

Code: Select all

<Script Language=JavaScript>

var currCount = 0;
var maxCount = 3;

function CountChecks(isBox){

  if (isBox.checked){currCount++}
  else {currCount--}
  if (currCount > maxCount)
   {
    alert('You may only select ' + maxCount + ' magazines for this package.');
    currCount--;
    isBox.checked = false;
   }
 
}



</Script>





How may I add that there must be 3 checked or else it won't go on???


:?
jamyers79
 
Posts: 0
Joined: Mon Aug 22, 2005 4:36 pm
Location: Florida, USA

Postby lalalogic on Sat Aug 27, 2005 7:26 pm

Code: Select all
<script Language="JavaScript">
<!--
function checkbox_checker()
{

// set var checkbox_choices to zero

var checkbox_choices = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
{

// If a checkbox has been selected it will return true
// (If not it will return false)
if (checkbox_form.checkbox[counter].checked)
{ checkbox_choices = checkbox_choices + 1; }

}


if (checkbox_choices > 3 )
{
// If there were more than three selections made display an alert box
msg="You're limited to only three selections.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-3) + " selection(s)."
alert(msg)
return (false);
}


if (checkbox_choices < 3 )
{
// If there were less then selections made display an alert box
alert("Please make three selections. \n" + checkbox_choices + " entered so far.")
return (false);
}

// If three were selected then display an alert box stating input was OK
alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}

-->
</script>


this might help you :) found here after a google search.
bahbye devppl :]
lalalogic
100+ Club
 
Posts: 200
Joined: Tue Aug 16, 2005 5:02 am


Who is online

Users browsing this forum: No registered users and 7 guests