Click to See Complete Forum and Search --> : Help with simple ASP page for school?


TheIconoclast
02-10-2009, 09:29 PM
Hey guys, I have to create a fairly simple ASP page for an assignment for my web management class and I seem to have run into a wall. I know the basics about ASP, and I am continuing to learn through W3Schools more advanced concepts. However, I can't seem to put together the knowledge that I have in order to complete this assignment as instructed.

Here is the task I have to complete:
Create a page that accepts the following information:
-10 different lab marks
-2 different project marks
-2 different test marks
-submit button
-reset button

Next, use VBScript to:
-when the submit button is clicked, store each value from the form into an array
-loop through the array
-add marks for labs
-add marks for projects
-add marks for tests
-output on the page: overall lab mark, project mark, and test mark
-use a nested if statement or select case statement to output the letter grade for the student's overall mark


Now, the part I'm having trouble with at the moment is how to store the values from the form textboxes in an array. We did a very similar project to this several weeks ago, but using JavaScript instead of ASP/VBScript. I know they are both similar, and perhaps someone can explain to me what differences there may be.

So far, my main body code looks like this (the red code is unfinished, as it is the part I need help with):
<%
dim i
for i=1 to 14
%>


<form name="lab2" method="post" action="lab2.asp">

<input type="text" name="lab1mark" />
<input type="text" name="lab2mark" />
<input type="text" name="lab3mark" />
<input type="text" name="lab4mark" />
<input type="text" name="lab5mark" />
<input type="text" name="lab6mark" />
<input type="text" name="lab7mark" />
<input type="text" name="lab8mark" />
<input type="text" name="lab9mark" />
<input type="text" name="lab10mark" />

<input type="text" name="project1mark" />
<input type="text" name="project2mark" />

<input type="text" name="test1mark" />
<input type="text" name="test2mark" />

<input type="submit" name="submit" value="Submit" />
<input type="reset" name="reset" value="Reset" />


<input type="text" name="outputlab" readonly="readonly" />
<input type="text" name="outputproject" readonly="readonly" />
<input type="text" name="outputtest" readonly="readonly" />

<input type="text" name="outputletter" readonly="readonly" />

</form>

I know the formatting isn't anything great, but I'm not concerned about that at this point (I want to get the code itself working properly before I deal with how it looks).

Now, as I mentioned above, we did a similar thing to this in a previous project in which we needed to populate the options of a drop-down menu from a JavaScript array. I'm not sure if this will be of any help, but I hope it might be:
function addOption(selectbox,text,value )

{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function addOption_list(selectbox)
{
var comicBooks = new Array("Batman","Spiderman","Hulk","X-Men","Superman");
for (var i=0; i < comicBooks.length;++i)
{
addOption(document.myForm.comicList, comicBooks[i], comicBooks[i]);
}
}


Can anyone help me out with this? I'd really appreciate it! :)

niceyellowegg
02-14-2009, 02:20 PM
To start off with, you will need to declare your array.

Dim myArray(13)

VBScript arrays start at element 0, so this array will hold all 14 values.
Populating the array is quite easy.

For the first 10 values

for i = 0 to 9
myArray(i) = trim(request.Form("lab" & (i + 1) & "mark"))
next

The Windows Script 5.6 Documentation (http://www.microsoft.com/downloads/details.aspx?familyid=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en) gives some pretty comprehensive information on arrays.

TheIconoclast
02-14-2009, 04:03 PM
What does the "trim" mean? (I'm assuming it's like the truncate, will cut off any decimals after a whole integer?)

Yes, I was doing more reading on ASP arrays and looping and came across this example...however I'm a bit confused by it, and wondering if anyone can explain it to me in more detail:

You can loop through all the values in a form request. If a user filled out a form by specifying two values - Blue and Green - for the color element, you could retrieve those values like this:

<%
for i=1 to Request.Form("color").Count
Response.Write(Request.Form("color")(i) & "<br />")
next
%>

Output:

Blue
Green

First of all, in the second line (following the <%), it has Request.Form("color")...What exactly is color in this sense? Is it the name of the form?

Because my HTML form has 14 different textboxes, all of which that have different names...how do you loop through all of the different textboxes with one loop even though the names are all different?

If my textboxes are named l1, l2, l3, etc. respectively for each lab textbox, and p1, p2, and t1, t2 for each project and test textbox respectively, then how would I loop through those elements with the Request.Form object? I spent quite some time trying to figure this out but so far it still remains a question to me.


Another question I have is: I have installed IIS7 on my Windows Vista Home Premium machine, and checked the box to enable ASP. However, when I click my submit button, it simply brings me to the .asp page and displays the unparsed asp code in the browser window. How do I fix that?

niceyellowegg
02-14-2009, 05:45 PM
Info on trim can be found here (http://www.w3schools.com/VBscript/func_trim.asp)

Info on the request command can be found here (http://www.w3schools.com/ASP/asp_inputforms.asp)

My previous example shows you how to loop through 10 of your text boxes, by inserting a variable/string combination into the request object.