Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

client side vbScript formcheck for multiple select box

Posted on 2002-07-08
4
Medium Priority
?
231 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 60 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Screencast - Getting to Know the Pipeline

916 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