Solved

client side vbScript formcheck for multiple select box

Posted on 2002-07-08
4
218 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

20 Experts available now in Live!

Get 1:1 Help Now