This topic is locked

Counting selected items

6/12/2006 3:54:20 PM
PHPRunner General questions
D
Dale author

I have a field flagged as a lookup based on a table.
Everything works fine.

I would like to be able to get the number of selected items and place the number in a field on the same form so I can do some calculations for pricing.
Can someone show me a snippet of code that could get me the Number of Selected items.

And just to add a bit of complexity, when a list item is selected or deselected I would like that counter field to be updated. I think I should be able to make the onChange for the field take care of the updating.
ps. Sorry to hear about this hacking crap. Looks like we lost some great posts.

Why cant we just all get along? I would like to see these hackers go to a site to get some info to find it was hacked by another hacker. Senseless.

Sergey Kornilov admin 6/12/2006

Here is the some sample code. I hope it helps.

<select id=... name=... onchange="var counter = 0;

for(i=0;i<this.options.length;i++) {

if(this.options[i].selected) counter++;

}

document.forms.editform.anotherfield.value = counter;

return true; "

D
Dale author 6/13/2006

Perfect,

Thanks Sergey.