Solved

client side vbScript formcheck for multiple select box

Posted on 2002-07-08
4
221 Views
Last Modified: 2008-02-01
I need to put the following javascript fromcheck into client side vbscript and I'm not sure of the syntex.
Basically the code needs to check that not more than 10 keywords have been selected before the form can be posted

for(i=0;i<document.form1.Keywords.length;i++)            
{      
  if(document.form1.Keywords[i].selected) iCount++;
             }
   if(iCount > 10)
              {
   mess = mess + "\nA maximum of 10 keywords";
            }    

}

Thanks
0
Comment
Question by:lambsan
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
KAbbott earned 30 total points
ID: 7138084
I think the best way to do this would be to create a hidden form value:

<input type="hidden" name="MyCount" value="">

Then
function YourFunction(){

for(i=0;i<document.form1.Keywords.length;i++)            
{      
 if(document.form1.Keywords[i].selected) iCount++;
            }
  if(iCount > 10)
             {
  mess = mess + "\nA maximum of 10 keywords";
  return false;
           }
 document.form1.MyCount = iCount;
 return true;
}

}
<form blah blah blah onSubmit="return YourFunction()">

In the server-side code just put:

If Request.Form("MyCount") > 10 Then

Response.Redirect("errorpage.asp")
'Or whatever

End If


Hope this helps

p.s can't remember if document.form1.MyCount should be document.form1.MyCount.value     give both a try if one doesn't work.
0
 

Author Comment

by:lambsan
ID: 7138482
Thanks for that,
Unfortunetly I don't think I can use this technique, as I'm using a clientside vbscript function to assign permissions to network folders but beofre I call this function, I need to check the form, both need to run before the form is submitted.

For Each strUser in Document.VolumeDetails.AssignUser
     MsgBox "Selected Users:" & Document.VolumeDetails.AssignUser.Value
     
Next
 I've put this together but it displays the message box for every item in the list (not every selected item) and then it just shows the first selected item,
Its driving me mad!

0
 

Author Comment

by:lambsan
ID: 7138532
Thanks for that,
Unfortunetly I don't think I can use this technique, as I'm using a clientside vbscript function to assign permissions to network folders but beofre I call this function, I need to check the form, both need to run before the form is submitted.

For Each strUser in Document.VolumeDetails.AssignUser
     MsgBox "Selected Users:" & Document.VolumeDetails.AssignUser.Value
     
Next
 I've put this together but it displays the message box for every item in the list (not every selected item) and then it just shows the first selected item,
Its driving me mad!

0
 

Author Comment

by:lambsan
ID: 7142804
Thanks for your suggestion,
I finally figured it out which is below in case anyone ever needs it

For Each objKeyword in TheForm.Keywords
     If objKeyword.selected Then
          i = i + 1
     End If
Next
If i > 10 Then
     strMessage = strMessage &  vbcrlf & "    -  A maximum of 10 Keywords"
     blnDataMissing = True
End If
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now