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

Posted on 1998-08-28
Last Modified: 2010-04-09
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??

Question by:erot
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
  • 5
  • 4
  • 3
LVL 28

Accepted Solution

sybe earned 150 total points
ID: 1837134
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 + ',';


Expert Comment

ID: 1837135
hmm i had not read your title that good, it is javascript not vbscript

Expert Comment

ID: 1837136
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1837137
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.


Author Comment

ID: 1837138
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.

Author Comment

ID: 1837139
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.

LVL 28

Expert Comment

ID: 1837140
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.

Author Comment

ID: 1837141
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.


LVL 28

Expert Comment

ID: 1837142
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.


Author Comment

ID: 1837143
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...


Expert Comment

ID: 1837144
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


Author Comment

ID: 1837145
Sybe and bluemon...Thank you for answering...
Can't do much about the delivery of points.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending ASP to server side 8 42
Adding 1 the value of input "text" every 3 seconds 5 48
Use Mid in Html 6 35
CSS question 4 56
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

737 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