General discussion

Locked

Count selected objects in form field on

By dmmoe ·
I have a form that has a scrolling text box with 20 names. I only want the user to be able to select 5 names. I am trying to write code that will pop up a dialog box that says "you can only select 5 names". I am also trying to run this when the client selects the Submit button.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Count selected objects in form field on

by E.Rick In reply to Count selected objects in ...

If you define a dropdown with your twenty names and set it to allow multiple selections you can determine the number of selected items with the Count property.

For example, if I have a SELECT field defined on my page called NameList, I can find out how many items are currently selected with the following statement:

Request.Form("NameList").Count

Collapse -

Count selected objects in form field on

by dmmoe In reply to Count selected objects in ...

The question was auto-closed by TechRepublic

Collapse -

Count selected objects in form field on

by mightyduk In reply to Count selected objects in ...

html:
<form action="blah blah" onsubmit="return checkcount();">

javascript (place in head of document):
<script language="javascript">
function checkcount(){
var count=0;
for (var i = 0; i < namelist.options.length; i++){
count+=namelist.options.selected;}
if(document.form.namelist.count>5){
alert("Error: You may select a maximum of 5 names");
return false;}
else{
return true;}
}
</script>

Collapse -

Count selected objects in form field on

by dmmoe In reply to Count selected objects in ...

The question was auto-closed by TechRepublic

Collapse -

Count selected objects in form field on

by Al Macintyre In reply to Count selected objects in ...

I program in other languages, but I would either have the names in an array or subfile so that I could either count non-blanks or loop check for non-blank & exit at 6, then return text box to user with what they selected with your error message.

Collapse -

Count selected objects in form field on

by dmmoe In reply to Count selected objects in ...

The question was auto-closed by TechRepublic

Collapse -

Count selected objects in form field on

by dmmoe In reply to Count selected objects in ...

This question was auto closed due to inactivity

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Software Forums