[Javascript] Checkboxes

Robert Pollard rpollard at apple.com
Mon Dec 8 19:33:44 CST 2003


Hi Clancy,

On Monday, December 8, 2003, at 04:38 PM, Clancy Jones wrote:

> Hi, I have a page that has several checkboxes on it which all have the 
> same name "Delete".  The page is a list of records which the user can 
> elect to delete or modify by checking the boxes and clicking a 
> relevant button.  I want the user to be able to select several records 
> to delete at one time if they wish but they should only be able to 
> select one record to modify at a time.  So I want to check when they 
> click the "Modify" button that they've selected one, and only one, 
> record.
>
> Can someone tell me how I can use Javascript to test whether one or 
> more than one of the checkboxes has been checked?

Try this code out.  It was used to see if the object was a checkbox and 
if the name of the checkbox matched "TermCode"  Put what you want into 
the condition.  All I did was record the element number into an array 
for future reference.

		for(var i = 0; i < document.forms[0].length; i++) {
		vType = document.forms[0].elements[i].type;
		vName = document.forms[0].elements[i].name;
		t = new String(vName);
			if((vType == 'checkbox') && (t.indexOf('TermCode') != -1)){
				// Append the form element index value to the end of the array
				aCBList[currentPos++] = i;
			}
		}

>
> Thanks a bunch,
> Clancy

HTH,

Robert Pollard

>
> _________________________________________________________________
> Need more speed?  Get Xtra Jetstream @  
> http://www.xtra.co.nz/products/0,,5803,00.html !
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list