Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Vbscript and ASP Problem - Expert Needed!

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,2158
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Vbscript and ASP Problem - Expert Needed! - 2/24/2005 5:32:27 AM   
  olimess

 

Posts: 12
Score: 0
Joined: 2/17/2005
From:
Status: offline
Hi everyone,

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.

You can take a look at my testing page here.

http://69.93.132.52/polylabel.com/test2.asp


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

orderTotal = 99
calculated = 0
subTotal = 0
tax = 0
total = 0
shippingCost = 0
shippingType = 0

%>

<!------ 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

' Display the results.
Document.form.lblShipCost.Caption = FormatCurrency(shipCost)
Document.form.lblShipType.Caption = shipType
Document.form.lblSubtotal.Caption = FormatCurrency(Subtotal)
Document.form.lblTaxes.Caption = FormatCurrency(AmountofTax)
Document.form.lblTotalCost.Caption = FormatCurrency(TotalCost)
end if
End sub
-->
</SCRIPT>
<tr>
<td><table><tr>
<td><br><input type=radio name="shippingcost" id="s1"> Airmail: </td>
<td align="right"><br> $5.00</td></tr>
<tr><td><input type=radio name="shippingcost" id="s2"> Standard: </td>
<td align="right"> $10.00</td></tr>
<tr><td><input type=radio name="shippingcost" id="s3"> 3-Day: </td>
<td align="right"> $16.00</td></tr>
<tr><td><input type=radio name="shippingcost" id="s4"> Overnight: </td>
<td align="right"> $20.00</td></tr></table></td></tr>
<tr><TD colspan=2><br><INPUT TYPE="Button" NAME=Calculate VALUE="Calculate Totals" onclick=cmdCalculate()><br><br></TD>
</TR>
<TR>
<TD>Shipping Cost:</TD>
<TD>
<OBJECT ID="lblShipCost" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"></OBJECT>
</TD>
</TR>
<TR>
<TD>Shipping Type:</TD>
<TD>
<OBJECT ID="lblShipType" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"></OBJECT>
</TD>
</TR>
<TR>
<TD>Subtotal:</TD>
<TD>
<OBJECT CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0" WIDTH=100 HEIGHT=24 ID="lblSubtotal"></OBJECT>
</TD>
</TR>
<TR>
<TD>Taxes:</TD>
<TD>
<OBJECT ID="lblTaxes" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"></OBJECT>
</TD>
</TR>
<TR>
<TD>Total Cost:</TD>
<TD>
<OBJECT ID="lblTotalCost" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"></OBJECT>
</TD>
</TR>
<tr><TD colspan=2><br><INPUT TYPE="Button" NAME=Validate VALUE="Complete Order" onclick=cmdValidate()></TD>
</TR>

<!------ Calculating Server Side and Setting Variables------>
<%
subTotal = subTotal + shippingCost
tax=subTotal*Session("TaxRate")
total=subTotal+tax
if shippingTypeCode = 1 then
shippingType = "Airmail"
elseif shippingTypeCode = 2 then
shippingType = "Standard"
elseif shippingTypeCode = 3 then
shippingType = "3-Day"
elseif shippingTypeCode = 4 then
shippingType = "Overnight"
else
shippingType = "Ship Samples"
end if
%>

<!------ Initial Value of Server Side Variables On Page Load ------>
<tr><td><table width="250" align="right" style="color: #FF0000;">
<tr>
<td><br>Server shippingCost: </td>
<td><br><%= shippingCost %> </td>
</tr>
<tr>
<td>Server shippingType: </td>
<td><%= shippingType %></td>
</tr>
<tr>
<td>Server subTotal: </td>
<td><%= subTotal %></td>
</tr>
<tr>
<td>Server tax:</td>
<td><%= tax %></td>
</tr>
<tr>
<td>Server total: </td>
<td><%= total %></td>
</tr>
</table>
</td></tr>
</TABLE>
</FORM>
</body>
</html>
 
 
Post #: 1
 
 Re: Vbscript and ASP Problem - Expert Needed! - 2/24/2005 5:38:11 AM   
  olimess

 

Posts: 12
Score: 0
Joined: 2/17/2005
From:
Status: offline
Oppps!!!

I should add ...

Even if you select a shipping option and press calculate ... this still happens ... the server-side variables are set to the last "case" statment.

On my real site I had a way of validating this by accessing my database.

Thanks again!

(in reply to olimess)
 
 
Post #: 2
 
 Re: Vbscript and ASP Problem - Expert Needed! - 3/2/2005 9:16:33 PM   
  VBS

 

Posts: 110
Score: 0
Joined: 3/2/2005
From: Lebanon
Status: offline
Dear olimess,
I love to help u but i didn't understand ur problem.
Please explain

Best Regards

Firas S Assaad

(in reply to olimess)
 
 
Post #: 3
 
 Re: Vbscript and ASP Problem - Expert Needed! - 3/9/2005 12:41:47 AM   
  dcampbell

 

Posts: 1
Score: 0
Joined: 3/9/2005
From:
Status: offline
Marhaban and Hello,

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.

=============================================================

<FORM NAME="form" onsubmit="serversideupdatepage">
<input type=hidden name=shipcost value=shippingcost>
<input type=hidden name=shiptypecode value=shippingtypecode>
<table>...........</table>......</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.

(in reply to olimess)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Vbscript and ASP Problem - Expert Needed! Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts