Solved

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

Posted on 1998-08-28
12
166 Views
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??


               
0
Comment
Question by:erot
  • 5
  • 4
  • 3
12 Comments
 
LVL 28

Accepted Solution

by:
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>"
Next
%>

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"
</form>

<script>
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 + ',';
         }
     }
  i++;
  }
  document.MyForm.HiddenField.value=strHiddenField;
}
</script>




0
 
LVL 1

Expert Comment

by:Bluemoon
ID: 1837135
hmm i had not read your title that good, it is javascript not vbscript
0
 
LVL 1

Expert Comment

by:Bluemoon
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:

HEE SOMEONE ELSE ANSWERD THE QUESTION BEFORE ME !!!!!
<HTML><SCRIPT>
function join()
{
 var val,i;
 
 val = "";
 for(i=0;i<document.form1.my_chk.length;i++)
   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;
}

</SCRIPT><BODY>

<FORM NAME=form1>
<INPUT TYPE=CHECKBOX NAME=my_chk VALUE=This CHECKED>This<BR>
<INPUT TYPE=CHECKBOX NAME=my_chk VALUE=is CHECKED>is<BR>
<INPUT TYPE=CHECKBOX NAME=my_chk VALUE=a>a<BR>
<INPUT TYPE=CHECKBOX NAME=my_chk VALUE=test CHECKED>test<BR>
<!-- and even more checkboxes named my_chk -->

</FORM>

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

let those 150 pnts come if you like my solution

Bluemoon
0
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.

 
LVL 1

Expert Comment

by:Bluemoon
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.

Bluemoon
0
 

Author Comment

by:erot
ID: 1837138
I'm still waiting for the book to arrive...I don't have the
syntax of VBScript.
(By the way...do 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.
0
 

Author Comment

by:erot
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.
 
 

0
 
LVL 28

Expert Comment

by:sybe
ID: 1837140
erot,
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:
Request.Form("name_of_the_form_field").

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.
0
 

Author Comment

by:erot
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 script...so 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.

Erot.


0
 
LVL 28

Expert Comment

by:sybe
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.


0
 

Author Comment

by:erot
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...

Erot
0
 
LVL 1

Expert Comment

by:Bluemoon
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
form.submit()

Bluemoon
0
 

Author Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mobile page Scrolling down when refreshing 4 61
Save ms data to server side. 19 55
Alert after MVC form submitted 1 22
multiple selects 23 48
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 is …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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