Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For loop for checkboxes

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,

Is there a way of creatng a for loop for checking the amount of checkboxes selected by a user.
Essentialy, what I'm trying to do is to capture an X and Y co-ordinate by allowing a user to select a checkbox. Using the values entered, I can then pass this onto an action form which will use the values entered and place the text/image specified by the the X and Y co-ordinates the user entered.

Any advice would be greatly appreciated.

Thanks
Sam
 
this is more of a javascript question

for (var m=0; m<document.elements.lenght; m++) {
if (document.elements[m].type==&quot;checkbox&quot; &amp;&amp; document.elements[m].checked) {
// great, this is a checkbox and it is checked - do whatever you have to !
}
}

it is possible to do that is cf, but be careful that only the checked checkboxes are passed
the point is that i don't know if there is a way to know the TYPE of a form element in cf
anyway, the list with all the form elements (but unchecked checkboxes !) is : form.FIELDNAMES
the NAME of an element in this list is : form.fieldnames[index]
the VALUE of the same element is : #Evaluate('#form.fieldnames[index]#')#

 
ma701sd,

Try this:

In header declare a Global Variable:
<head>
<script>
var checkboxes = 0;
function numberCheckboxes()
{
for (var i=0; m<document.formname.fieldname.length; m++)
{
if (document.formname.fieldname.checked) {
{
x = x + 1;
}
}
return true;
}
</script>
</head>

<body>
<form blah, blah, blah>

....
<script>
numberCheckboxes();
</script>
<cfif (#checkboxes# > 0)
(((action)))
</cfif>
...............
</form> ((etc.))

Hope it helps,
pjbarteck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top