All Forums >> [Scripting] >> ASP >> Vbscript and ASP Problem - Expert Needed! Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I'm fairly new ASP and VBScript so please bare with me. I'm having an issue using a VBScript (client side) and ASP together.
Basically I have this piece of testing code (sampled from my site) where the "Order Total" is obtained from the server. In my code I just declare an "Order Total" server side variable and set it myself.
As you can see, I have radio buttons where you can select the shipping options. Once you do, you press calculate and the totals are listed. I use a VBScript client-side "Case statement" for this. As you can see in the "Case Statement" from the code below, I am setting both client-side and server-side variables from within my case.
In the fully working model the server-side variables will be saved to a database.
What you will notice however, is that when the page first loads, some of the server-side variables have already been set even though the "Case" script has never been activated. You can see this at the very bottom of the "test2.asp" page in red. This tells me that ASP ignores the client-side VBscript "Case" script and sets the server-side variables until it reach the end of the code. This results in the variables being set from the last "case" statement .
I guess my question is ... how do I fix this problem? Please help! ahahha. It never hurts to beg from time to time.
Here is the code:
<HTML> <HEAD>
<!------ VBSCRIPT VALIDATE CALCULATE BUTTON HAVE BEEN PRESSED ------> <SCRIPT LANGUAGE="VBScript"> dim calculated calculated = 0 Sub cmdValidate if calculated = 0 then msgbox "Please Select Shipping Option and Press the 'Calculate Totals' Button" else msgbox "Order Complete!" end if End sub --> </SCRIPT>
</HEAD> <BODY>
<!------ Declaring Server Side Variables ------> <% Dim orderTotal Dim calculated dim subTotal dim tax dim total dim shippingCost dim shippingType
<!------ Calculate Form ------> <FORM NAME="form"> <TABLE><tr><td>Initial Order Total is: $<%= orderTotal %><br><br></td></tr> <TR><TD><B>Shipping Options:</B><Br></TD></tr>
<!------ VBScript Shipping Routine ------> <SCRIPT LANGUAGE="VBScript"> <!-- Dim shipCost Dim shipType Dim Tax Dim Subtotal Dim TAX_RATE Dim TotalCost Dim shipSelected
shipSelected = 0 TAX_RATE = 0.06
Sub cmdCalculate Select Case TRUE Case document.all.s1.Checked <!------ Server Side Variables Being Set ------> <% shippingCost=5 shippingTypeCode=1 %> calculated=1 shipCost = 5 shipType = "Airmail" shipSelected = 1 Case document.all.s2.Checked <!------ Server Side Variables Being Set ------> <% shippingCost=10 shippingTypeCode=2 %> calculated=1 shipCost = 10 shipType = "Standard" shipSelected = 1 Case document.all.s3.Checked <!------ Server Side Variables Being Set ------> <% shippingCost=16 shippingTypeCode=3 %> calculated=1 shipCost = 16 shipType = "3-Day" shipSelected = 1 Case document.all.s4.Checked <!------ Server Side Variables Being Set ------> <% shippingCost=20 shippingTypeCode=4 %> calculated=1 shipCost = 20 shipType = "Overnight" shipSelected = 1 Case Else msgbox "Please Select Shipping Option" End Select
if shipselected = 1 then ' Perform order calculations. Subtotal = (<%= orderTotal %>) + ShipCost AmountofTax = Subtotal * TAX_RATE TotalCost = Subtotal + AmountofTax
I think his problem comes from an incomplete understanding of how the server and client sides work together. I'm still learning this myself, so please pardon me if I'm mistaken here.
The ASP page, once you serve it up to the user, cannot make changes to the server side variables until you post the contents of the form back to the server.
One way to post these values back to the server is to include them explicitly in the INPUT tags in the form.
The secondary page should have some server side SQL code to update the database. The secondary page will be able to access those values via request.form("shipcost") and request.form("shiptypecode").
I would love to tell you all about how to put an ACTION="cgiscriptname" clause in the form, but I haven't learned to do that myself yet.