Solved

client side vbScript formcheck for multiple select box

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSON error 4 71
Hide row when retrieving data from database 6 68
How to show result of a NULL value at random? 33 57
Save ms data to server side. 19 55
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 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