Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

Fast answer please....How to use VBScript to check FormValues

I use an ASP-page to generate a page consisting of:
One frame consisting of unknown numbers of CheckBoxes
(because they are generated dynamically), some other text-
fields and a submit-button.

When the Submit-button are choosed by the user I want,
on the Click-event on that button, to generate a comma-
separated string of the names of the checked CheckBoxes and
put the string in a hidden text-field in the same frame.

I want all this done before the click on the submit-button
gives control to the ASP-page in the form's ACTION.

Short: I'm looking for a way to go trough all the checked
CheckBoxes without knowing in beforehand how many checkBoxes
there are, and generate a Comma-separated list of the Check-
boxes name,before the control are given to the ASP-file with the submit-button.
 Is this possible to do?????

I know about the request.form syntax that can be used in
ASP-page referenced in the form's ACTION, but this is not
the best solution for me.
                If there is a solution to this.... this
          question will be upgraded to 150 pnts if it can
        solve my problem.

Good luck. I use FrontPage98, ASP, Access and VBScript.
If it's not possible in VBScript...what about other scripts
such as Java-script??

  • 5
  • 4
  • 3
1 Solution
In the first place this is possible using javascript.

Secondly: why would you want to do this: if you use the same name for all the checkboxes, then it is done more or less automatically: you'll get a querystring (if the form method is "GET") like "?CheckBoxName=value1,value2,value3". Where only the values of the checked boxes will be represented.

It can be easily parsed in ASP using:

For each value in Request.Querystring("CheckBoxName")
   Response.write value & "<br>"

It is much harder to parse the value of the hidden field you want to use. Furthermore the javascript solution is browser dependent, and probably won't work in MSIE3.

But ok:

<form name="MyForm" onSubmit="WriteHiddenField()">
<input type"hidden" name="checkboxstring">

your fields

<input type="submit"

function WriteHiddenField () {
  var strHiddenField = "";
  i = 0;
  while (i < document.MyForm.length) {
     if(document.MyForm.elements[i].type='checkbox') {
         if(document.MyForm.elements[i]) {
         strHiddenField = strHiddenField + document.MyForm.elements[i].value + ',';

hmm i had not read your title that good, it is javascript not vbscript
I solved your problem, and it is possible, you make as many checkboxes as you need in one form and make a second form, you'd submit that makes the comma seperated list.
A for-loop makes sure you dont have to know how many there are just give them the same
name and an array is made.

here is the code:

function join()
 var val,i;
 val = "";
   if (document.form1.my_chk[i].checked)
     val += document.form1.my_chk[i].value + ",";
 // save it in the hidden field of the other form
 document.form2.my_chk_list.value = val;


<FORM NAME=form1>
<!-- and even more checkboxes named my_chk -->


<FORM NAME=form2 method=POST onsubmit="alert('submitting: list = '+                                                                          document.form2.my_chk_list.value)">
<INPUT TYPE=SUBMIT Onclick="join()" VALUE="Submit">

let those 150 pnts come if you like my solution

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

O well let Erot fight out who gets the points

Sybe and I haven't seen each others answers and answered the question independetly

mayby you can share the points, Erot, post a question for Bluemoon in the same group for part of the points or ask the EE.

erotAuthor Commented:
I'm still waiting for the book to arrive...I don't have the
syntax of VBScript.
(By the you know any good ASP books for professionals.
I have ordered : Professional Active Server Pages 2.0 (Wrox))

Back to my problem....
Can you please send me the syntax for the
   FORM GET Method....
   If there is a difference between the syntax in a called
   ASP-file and feks if the code on a buttons Click-event please
   show me both syntaxes.
erotAuthor Commented:
This was To Sybe.

Can you please send me the syntax for the
   FORM GET Method....
   If there is a difference between the syntax in a called
   ASP-file and feks if the code on a buttons Click-event please
   show me both syntaxes.

I am not sure if I understand your question now. But I'll try to answer it:

1. Submitting a form can be done by "POST" and by "GET". GET is default. GET produces a querystring, POST sends the data to the server from which they can be gotten by "asking" the server in your script. To indicate what you want to do with the from, it should be included in the form-tag (with method=...):
<FORM action="your_page.asp" METHOD="GET">

2. When a form is submitted to an ASP, then that ASP can use the formdata which have been submitted. When the method was "GET", then the formdata can be fetched by Request.Querystring("name_of_the_form_field").
If the method was POST then it is:

If you are not sure about the method, you can use Request("name_of_the_formfield")

I hope this answers your questions, but again, I am not sure what you ask.
erotAuthor Commented:
Thank You Sybe and Bluemoon...
You to have been very energic  ....
I can see that the question can be missunderstood?!?!?!

Even shorter: Before the form is submitted I want to put a
  commas-eparated list of the names of """only""" the checked
  Check-boxes and put the result in a hidden field in the form.
  As posted before I do not know the names of the check-boxes
  on the form or how many, when I write the the
  script have to be general.

Thank you for your answer so far...I'l try to figure out if the
answers you have given me can be used..Then I'l come back to you.


Ok, check the answers given, and see if they do.

I still think that there is a better way to achieve what you want then with the way you want to solve it. But then again, I don't know exactly what you want to achieve.

It would be helpful if you'd post the ASP-code of the page that generates the form with the checkboxes, and the code of the page that will process the formdata. I guess that will make clear what you want to achieve.

erotAuthor Commented:
this code works perfectly well on the corresponding ASP-page
on the server.

dim checkValues
checkValues = request.form("C1")
'where C1 are the names of all the checkBoxes on the page.
if the client checked any of the CheckBoxes the variable
checkValues are equal to a commaseparate string of the values
to the checked CheckBoxes.  But is it really not possible to
produce the same commaseparated string with code running on
the client (script within the page that are shown on the client).
If it was it would simplify my code a great deal.

The reason... I want to verify what the user checked, give him
a message where he can submit or cancel. I want to show this message in a messageBox not a new Page...

If you don't know the names of the checkboxes, the method Sybe used would work
and if you like the have 'only' the hidden value, you would have to use a seperate form
you can even remove the text the 'submit' button sends by making it a normal button
and at the end of the javascript something like

erotAuthor Commented:
Sybe and bluemon...Thank you for answering...
Can't do much about the delivery of points.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now