Solved

client side vbScript formcheck for multiple select box

Posted on 2002-07-08
4
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiflying 2 Input Text On a Table 7 37
Debugging Html 8 44
Sending ASP to server side 8 44
GitHub 1 41
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 informatio…
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/…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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