Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 1st, 2004, 12:38 PM
Registered User
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cash Register web form

I an new and I an stuck. I'm using Microsoft Visual Studio 2003 to create a simple form for a class project. The form needs to conform to the following sequence:

1) User inputs a retail price
2) User checks off Employee discount of 25%(where applicable)
3) User selects location from drop-down box
4) User presses calculation button to retrieve TOTAL price

Here's my syntax. Dont laugh. What went wrong? I need the calcualtion to work and for the info to REMAIN on the screen AFTER the user presses the Calculate Total button.

Thanks so much. Please post here or to my email:
activexcode@hotmail.com.

I need an answer before 4PM today. Thanks for your expertise! :-)


<%
DIM retailprice, location, employeediscount, calculatetotal, runningtotal

retailprice = request.form("retailprice")
location = request.form("location")
employeediscount = request.form("employeediscount")'This is a checkbox variable.
calculatetotal = request.form("calculatetotal")'Should calculate when button is pressed
discount = request.form("discount")
runningtotal = retailprice
'Use commands to view variables at top of page:
response.write("retail price is: " & retailprice & "<br/>")
response.write("location is: " & location & "<br/>")
response.write("runningtotal is: " & runningtotal & "<br/>")

if employeediscount = "on" then
    runningtotal = retailprice * (1 - .25)
else runningtotal = retailprice
end if
calculatetotal = (location * retailprice)+ retailprice
response.write("Total amount due is $" & calculatetotal & "<br/>")

%>
    <form method= "post" action= "CashRegister.asp">

    <h4>Retail Price:</h4>
    <input type="text" name="Retail Price" value="<% =retailprice%>"<br/>
    <h4>Use Employee Discount?:</h4>
    <input type ="checkbox" name="Employeediscount" value ="checkbox"/><br/>
    <h4>Location (for sales tax):</h4>
    <select name= "Location">
        <option value="0">Delaware</option>
        <option value=".06">New Jersey</option>
        <option value=".06">Pennsylvania</option>
        <option value=".07">PA - Philadelphia</option>
    </select>
    <p>
    <input type= "submit" value="Calculate Total" name="calculatetotal"/>
    </p>
    <input type="hidden" value=".25" name="discount"/>
    </form>

    </body>
</html>


 
Old October 2nd, 2004, 12:36 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Cool. I have corrected the code for you. Here is the corrected code.

--------------------------------------------------------------------------

<%
DIM retailprice, location, employeediscount, calculatetotal, runningtotal, locationprice

retailprice = request.form("RetailPrice")
location = request.form("Location")
Select case location
    case "Delaware"
        locationprice=0.0
    case "New Jersey"
        locationprice=0.06
    case "Pennsylvania"
        locationprice=0.06
    case "PA - Philadelphia"
        locationprice=0.07
    case else
        locationprice=0.0
end select
employeediscount = request.form("Employeediscount")'This is a checkbox variable.
calculatetotal = request.form("calculatetotal")'Should calculate when button is pressed
discount = request.form("discount")
runningtotal = retailprice
'Use commands to view variables at top of page:
response.write("retail price is: " & retailprice & "<br/>")
response.write("location is: " & location & "<br/>")
response.write("runningtotal is: " & runningtotal & "<br/>")

Response.Write("Whether discount applicable ?")

if employeediscount = "on" then
    Response.Write("Yes<br />")
        runningtotal = retailprice * (1 - .25)
else
    Response.Write("No<br />")
    runningtotal = retailprice
end if
calculatetotal = (locationprice * runningtotal)+ runningtotal
response.write("Total amount due is $" & calculatetotal & "<br/>")

%>
    <form method= "post" action= "CashRegister.asp">

    <h4>Retail Price:</h4>
    <input type="text" name="RetailPrice" value="<% =retailprice%>"><br/>
    <h4>Use Employee Discount?:</h4>
    <%if employeediscount = "on" then%>
        <input type ="checkbox" name="Employeediscount" checked /><br/>
    <%else%>
    <input type ="checkbox" name="Employeediscount" /><br/>
    <%End if%>
    <h4>Location (for sales tax):</h4>
    <select name= "Location">
    <%if(Request.Form("Location")="Delaware") Then %>
               <option value="Delaware" selected>Delaware</option>
    <%else%>
        <option value="Delaware">Delaware</option>
    <%end if%>
    <%if(Request.Form("Location")="New Jersey") Then %>
               <option value="New Jersey" selected>New Jersey</option>
    <%else%>
        <option value="New Jersey">New Jersey</option>
    <%end if%>
    <%if(Request.Form("Location")="Pennsylvania") Then %>
               <option value="Pennsylvania" selected>Pennsylvania</option>
    <%else%>
        <option value="Pennsylvania">Pennsylvania</option>
    <%end if%>
    <%if(Request.Form("Location")="PA - Philadelphia") Then %>
               <option value="PA - Philadelphia" selected>PA - Philadelphia</option>
    <%else%>
        <option value="PA - Philadelphia">PA - Philadelphia</option>
    <%end if%>
    </select>
    <p>
    <input type= "submit" value="Calculate Total" name="calculatetotal"/>
    </p>
    <input type="hidden" value=".25" name="discount"/>
    </form>

    </body>
</html>

----------------------------------------------------------------------

The problems were :

1) The name for the textbox and name used in request.form were different.

2) The input tag was not closed

3) The ides of giving lication price as the value of option box will not help in autoselecting the chosen option box.
 
Old October 2nd, 2004, 04:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi activexcode,

Just wanted to add to Madhu's suggestions.

1) You can simplify the IF/ELSE conditions within the <SELECT> tag used, as shown below. This would execute the SELECTED code only when the dropdown Item's value matches the value posted from the form.

2) Than using Request.Form within every IF/ELSE, you could do that once before the SELECT tag and store it in a variable, so that it doesn't have to contact server for requesting this value again and again.

3) Readablilty.
Code:
strLocation = Request.Form("Location")

<select name= "Location">
        <option value="Delaware" <% If strLocation = "Delaware" then %> selected <% End If %>>Delaware</option>
        <option value="New Jersey" <% If strLocation = "New Jersey" then %> selected <% End If %>>New Jersey</option>
        <option value="Pennsylvania" <% If strLocation = "Pennsylvania" then %> selected <% End If %>>Pennsylvania</option>
        <option value="PA - Philadelphia" <% If strLocation = "PA - Philadelphia" then %> selected <% End If %>>PA - Philadelphia</option>
</select>
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old October 2nd, 2004, 10:54 PM
Registered User
 
Join Date: Oct 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your code lists the locations TWICE in the drop-down box. I only want each location to appear once. Also, there should be only one Employee discount check box, not two. Last, the form didn't calculate. :-(

 
Old October 3rd, 2004, 05:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Whose code you mean? Can you post your code here?

Looks like you are mixing up with something there. I assume you should be using your own <OPTION> tags + the <option> tags that was posted here.

Same should be the case with the checkbox.;)

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cash Register arcadium Java GUI 0 August 2nd, 2008 10:24 PM
accessing Electronic Cash Register memory programmer.cse BOOK: Excel 2003 VBA Programmer's Reference 0 July 23rd, 2008 03:53 PM
Controling Cash Register With VBA Code wkalo Access ASP 5 July 22nd, 2008 07:07 PM
register.php: clearing html form fields lamada BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 26th, 2004 01:25 PM
Form allows multiple user to register same userid shresthaal ADO.NET 1 May 12th, 2004 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.