Current location: Hot Scripts Forums » Programming Languages » ASP » Problem With Form Calculation


Problem With Form Calculation

Reply
  #1 (permalink)  
Old 03-25-04, 11:49 AM
franzi franzi is offline
New Member
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Problem With Form Calculation

Hi I am new to asp and I am trying to figure out how to make a
order form. Everything seems to work fine exept when I use + to get
the total price.

Example: item1(price=10) + item2(price=10) = total: 20
instead of 20 I get total: 2020

When I use - then everything is working right

Here is the script that is not working:
<% = (strsamtals + strsamtals2) %>
<% =(strvsk + strvsk2) %>

Here is the code:
<%
Dim strnafn, strkennitala, strheimili, strheimasimi, strgsmsimi, strvinnusimi, strfax, strvegna, strath, strofnategund, strhaed, strlengd, strstutastaerd, strstutastadsetning, strverd, strstk, strsamtals, strvsk, strofnategund2, strhaed2, strlengd2, strstutastaerd2, strstutastadsetning2, strverd2, strstk2, strsamtals2, strvsk2

strofnategund2 = Request.Form("ofnategund2")
strhaed2 = Request.Form("haed2")
strlengd2 = Request.Form("lengd2")
strstutastaerd2 = Request.Form("stutastaerd2")
strstutastadsetning2 = Request.Form("stutastadsetning2")
strverd2 = Request.Form("verd2")
strstk2 = Request.Form("stk2")
strsamtals2 = Request.Form("samtals2")
strvsk2 = Request.Form("vsk2")

Response.Cookies("runtyl")("ofnategund2") = strofnategund2
Response.Cookies("runtyl")("haed2") = strhaed2
Response.Cookies("runtyl")("lengd2") = strlengd2
Response.Cookies("runtyl")("stutastaerd2") = strstutastaerd2
Response.Cookies("runtyl")("stutastadsetning2") = strstutastadsetning2
Response.Cookies("runtyl")("verd2") = strverd2
Response.Cookies("runtyl")("stk2") = strstk2
Response.Cookies("runtyl")("samtals2") = strsamtals2
Response.Cookies("runtyl")("vsk2") = strvsk2

strnafn = Request.Cookies("runtyl") ("nafn")
strkennitala = Request.Cookies("runtyl")("kennitala")
strheimili = Request.Cookies("runtyl")("heimili")
strheimasimi = Request.Cookies("runtyl")("heimasimi")
strgsmsimi = Request.Cookies("runtyl")("gsmsimi")
strvinnusimi = Request.Cookies("runtyl")("vinnusimi")
strfax = Request.Cookies("runtyl")("fax")
strvegna = Request.Cookies("runtyl")("vegna")
strath = Request.Cookies("runtyl")("ath")
strofnategund = Request.Cookies("runtyl")("ofnategund")
strhaed = Request.Cookies("runtyl")("haed")
strlengd = Request.Cookies("runtyl")("lengd")
strstutastaerd = Request.Cookies("runtyl")("stutastaerd")
strstutastadsetning = Request.Cookies("runtyl")("stutastadsetning")
strverd = Request.Cookies("runtyl")("verd")
strstk = Request.Cookies("runtyl")("stk")
strsamtals = Request.Cookies("runtyl")("samtals")
strvsk = Request.Cookies("runtyl")("vsk")

strnafn2 = Request.Cookies("runtyl") ("nafn2")
strkennitala2 = Request.Cookies("runtyl")("kennitala2")
strheimili2 = Request.Cookies("runtyl")("heimili2")
strheimasimi2 = Request.Cookies("runtyl")("heimasimi2")
strgsmsimi2 = Request.Cookies("runtyl")("gsmsimi2")
strvinnusimi2 = Request.Cookies("runtyl")("vinnusimi2")
strfax2 = Request.Cookies("runtyl")("fax2")
strvegna2 = Request.Cookies("runtyl")("vegna2")
strath2 = Request.Cookies("runtyl")("ath2")
strofnategund2 = Request.Cookies("runtyl")("ofnategund2")
strhaed2 = Request.Cookies("runtyl")("haed2")
strlengd2 = Request.Cookies("runtyl")("lengd2")
strstutastaerd2 = Request.Cookies("runtyl")("stutastaerd2")
strstutastadsetning2 = Request.Cookies("runtyl")("stutastadsetning2")
strverd2 = Request.Cookies("runtyl")("verd2")
strstk2 = Request.Cookies("runtyl")("stk2")
strsamtals2 = Request.Cookies("runtyl")("samtals2")
strvsk2 = Request.Cookies("runtyl")("vsk2")

%>

<div id="Layer3" style="position:absolute; left:22px; top:55px; width:540; z-index:14">
<table border="1" cellpadding="4" cellspacing="2" bordercolor="#000000">
<form name="form1" method="post" action="panta_runtyl3.asp">
<tr>
<td align="left" valign="middle"><strong>Nafn:</strong>
</td>
<td colspan="6" align="left" valign="middle"> <% =(strnafn) %> </td>
</tr>
<tr>
<td align="left"><strong>Kennitala:</strong></td>
<td colspan="6" align="left"> <% =(strkennitala) %> </td>
</tr>
<tr>
<td align="left"><strong>Heimili:</strong></td>
<td colspan="6" align="left"> <% =(strheimili) %> </td>
</tr>
<tr>
<td align="left"><strong>Heimas&iacute;mi:</strong></td>
<td colspan="6" align="left"> <% =(strheimasimi) %> </td>
</tr>
<tr>
<td align="left"><strong>Gsms&iacute;mi:</strong></td>
<td colspan="6" align="left"> <% =(strgsmsimi) %> </td>
</tr>
<tr>
<td align="left"><strong>Vinnus&iacute;mi:</strong></td>
<td colspan="6" align="left"> <% =(strvinnusimi) %> </td>
</tr>
<tr>
<td align="left"><strong>Fax:</strong></td>
<td colspan="6" align="left"> <% =(strfax) %> </td>
</tr>
<tr>
<td align="left"><strong>Vegna:</strong></td>
<td colspan="6" align="left"> <% =(strvegna) %> </td>
</tr>
<tr>
<td align="left"><strong>Ath:</strong></td>
<td colspan="6" align="left"> <% =(strath) %> </td>
</tr>
<tr>
<td colspan="7" bgcolor="#CCCCCC"><input name="imageField" type="image" src="../images/spacer.gif" width="100" height="10" border="0"></td>
</tr>
<tr>
<td width="104"><strong>Ofnategund</strong></td>
<td width="42"><strong>H&aelig;&eth;</strong></td>
<td width="56"><strong>Lengd</strong></td>
<td width="47"><strong>Stutast&aelig;r&eth;</strong></td>
<td width="48"><strong>Stutasta&eth;setning</strong></td>
<td width="22"><strong>Stk</strong></td>
<td width="53"><strong>Ver&eth;</strong></td>
</tr>
<tr>
<td> <% =(strofnategund) %> </td>
<td> <% =(strhaed) %> </td>
<td> <% =(strlengd) %> </td>
<td> <% =(strstutastaerd) %> </td>
<td> <% =(strstutastadsetning) %> </td>
<td> <% =(strstk) %> </td>
<td> <% =(strverd) %> </td>
</tr>
<tr>
<td>
<% =(strofnategund2) %>
</td>
<td>
<% =(strhaed2) %>
</td>
<td>
<% =(strlengd2) %>
</td>
<td>
<% =(strstutastaerd2) %>
</td>
<td>
<% =(strstutastadsetning2) %>
</td>
<td>
<% =(strstk2) %>
</td>
<td>
<% =(strverd2) %>
</td>
</tr>
<tr>
<td colspan="7" bgcolor="#CCCCCC"><input name="imageField2" type="image" src="../images/spacer.gif" width="100" height="10" border="0"></td>
</tr>
<tr>
<td colspan="5" align="right"><strong>Samtals kr.</strong></td>
<td colspan="2"> <% = (strsamtals + strsamtals2) %> </td>
</tr>
<tr>
<td colspan="5" align="right"><strong>&THORN;ar af Vsk.</strong></td>
<td colspan="2"> <% =(strvsk + strvsk2) %> </td>
</tr>
<tr>
<td colspan="7" align="left"><strong>
<input type="button" value="Prenta" onclick="window.print()" name="B2">
</strong> </td>
</tr>
</form>
</table>
<br>
</div>
Reply With Quote
  #2 (permalink)  
Old 03-25-04, 01:02 PM
Shane Shane is offline
Coding Addict
 
Join Date: Jun 2003
Location: Maryland, US
Posts: 268
Thanks: 0
Thanked 0 Times in 0 Posts
Make sure all data types entered are numeric. In other words, wrap each form request and cookie request in the CLng function.

For example..

Code:
MyValue = CLng(Request.Cookies("somecookie")("something"))
and

Code:
MyValue = CLng(Request.Forms("form_name")
__________________
Shane Bauer
Microsoft Certified Professional (MCP) - ASP.NET
ASP/ASP.net, C#, VB/VB.NET, PHP, Perl, SQL
Reply With Quote
  #3 (permalink)  
Old 03-25-04, 04:17 PM
franzi franzi is offline
New Member
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I have tried your example but get this error message:
Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CLng'

/panta_ofn/samlagt2.asp, line 5


Quote:
Originally Posted by Shane
Make sure all data types entered are numeric. In other words, wrap each form request and cookie request in the CLng function.

For example..

Code:
MyValue = CLng(Request.Cookies("somecookie")("something"))
and

Code:
MyValue = CLng(Request.Forms("form_name")
Reply With Quote
  #4 (permalink)  
Old 03-26-04, 04:10 AM
MadDog MadDog is offline
Code Master
 
Join Date: Aug 2003
Posts: 935
Thanks: 0
Thanked 0 Times in 0 Posts
If your getting a Clng error that means that the thing that you are trying to convert to a number is Null. So you need to make sure that cookie is being set to a number (even if its zero).

Then you wont get the Clng errors and the math will be computed properly.
__________________
Drew Gauderman
ASP - MSSQL Coder / Buisness Owner / Coder for Hire!
MSN-ICQ-AIM-YIM in Profile

http://www.iportalx.net an easy ASP portal system.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with date in combobox. Periodically lose valu Danie Visual Basic 1 03-04-04 02:41 PM
how do i re-fill the html form??? gaurav_sting PHP 1 12-21-03 12:13 PM
submit form? tcooper PHP 5 12-12-03 03:30 PM
can't figure out this form problem spyny JavaScript 1 12-12-03 09:53 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 03:49 AM


All times are GMT -5. The time now is 04:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.