Modify the book store to use an HTML form using HTTP POST instead of the XMLHttpRequest object.

What will be an ideal response?


The first table contains submit.asp, the second table contains theItems.js and the third table contains
index.html.

```
1 <% @Language = "VBScript" %>
2 <% Option Explicit %>
3 <% Response.Expires = 0 %>
4 <%
5 ' Exercise 28.4: submit.asp
6
7 Dim objConn, objRS, sql, errorMessage, i, strCart
8 Dim storeFrontOrderID, storeFrontOrderDate, customerID
9
10 If Request( "xml" ) <> Empty Then
11 strCart = Request( "xml" )
12 Else
13 Call Response.Redirect( "index.html" )
14 End If
15
16 If Request( "cmdButton" ) = "Cancel" Then
17 Call Response.Redirect( "index.html" )
18 End If
19
20 If Request( "cmdButton" ) = "Submit" Then
21 If Request( "txtUser" ) <> Empty And _
22 Request( "txtPass" ) <> Empty Then
23
24 Set objConn = Server.CreateObject( "ADODB.Connection" )
25 Set objRS = Server.CreateObject( "ADODB.RecordSet" )
26 Call objConn.Open( "DSN=dbStorefront" )
27 sql = "SELECT * FROM Customer WHERE userid = '" & _
28 Request( "txtUser" ) & "' AND password = '" & _
29 Request( "txtPass" ) & "'"
30
31 Call objRS.Open( sql, objConn, 1, 2 )
32
33 If objRS.RecordCount > 0 Then
34 Session( "storeFrontLoggedIn" ) = objRS( "customerid" )
35 customerID = objRS( "customerid" )
36 Call objRS.Close()
37
38 objRS.ActiveConnection = objConn
39 objRS.Source = "Orders"
40 objRS.CursorType = 1 ' adOpenKeyset
41 objRS.LockType = 2 ' adLockPessimistic
42 Call objRS.Open()
43
44 Call objRS.AddNew()
45 objRS( "orderdate" ) = Now
46 objRS( "product_xml" ) = strCart
47 objRS( "verified" ) = True
48 objRS( "customerid" ) = customerID
49 objRS( "total_cost" ) = Request( "total" )
50 Call objRS.Update()
51 Call objRS.Close()
52
53 ' Finished
54 Session( "error" ) = "Order complete. " & _
55 "Thank You for your purchase."
56 Call Response.Redirect( "account.asp" )
57 Else
58 Call objRS.Close()
59 Call objConn.Close()
60 Session( "storeFrontLoggedIn" ) = Empty
61 errorMessage = "Invalid Username / Password pair."
62 End If
63 Else
64 Session( "storeFrontLoggedIn" ) = Empty
65 errorMessage = "Invalid Username / Password pair."
66 End If
67 End If
68 %>
69
70
71
72
73
74 StoreFront
75
76
78
79
80
81

82 CELLSPACING = "0" BORDER = "0" BGCOLOR = "#67CDFF">
83
84
87
88
89
231
232
233
236
237
85 SRC = "images/header2.jpg" WIDTH = "750"
86 HEIGHT = "35">

90

Please confirm your order

91

<% =errorMessage %>


92

93 94 CELLSPACING = "0" BORDER = "0"
95 ID = "shoppingCart">
96
97
100
103
106
110
111
115
119
120 <%
121 Dim newInfo, newInfoRoot, theTotal, product
122 Dim prodISBN, prodAuthor, prodTitle, prodQuantity, prodPrice
123 Dim prodTotal
124
125 Set objConn = Server.CreateObject( "ADODB.Connection" )
126 Set objRS = Server.CreateObject( "ADODB.RecordSet" )
127 Call objConn.Open( "DSN=dbStorefront" )
128
129 Set newInfo = Server.CreateObject( "Microsoft.XMLDOM" )
130 newInfo.Async = False
131 Call newInfo.LoadXML( strCart )
132
133 Set newInfoRoot = newInfo.DocumentElement
134
135 theTotal = 0
136
137 For i = 0 To ( newInfoRoot.ChildNodes.Length - 1 )
138 Set product = newInfoRoot.ChildNodes.Item( i )
139 prodISBN = product.GetAttribute( "isbn" )
140
141 ' Search the DB for the prodID.
142 sql = "SELECT * FROM Products WHERE isbn = '" & _
143 prodISBN & "'"
144 Call objRS.Open( sql, objConn, 1, 2 )
145
146 ' Fill in the rest of the items.
147 prodAuthor = objRS( "author" )
148 prodTitle = objRS( "title" )
149 prodPrice = objRS( "price" )
150 prodPrice = FormatNumber( prodPrice, 2 )
151 prodQuantity = product.getAttribute( "qty" )
152 prodTotal = prodPrice * prodQuantity
153 prodTotal = FormatNumber( prodTotal, 2 )
154 theTotal = theTotal + prodTotal
155 Call objRS.Close
156 %>
157
158
160
162
164
167
168
171
174
175 <%
176 Next
177
178 theTotal = FormatNumber( theTotal, 2 )
179 %>
180
181
182
183
184
185
186
190
193
194

98 ISBN
99

101 Author
102

104 Title
105
107 CLASS = "label">
108 Price
109
112 CLASS = "label">
113 Quantity
114
116 CLASS = "label">
117 Total
118

159 <% =prodISBN %>

161 <% =prodAuthor %>

163 <% =prodTitle %>
165 VALIGN = "top">
166 $<% =prodPrice %>
169 VALIGN = "top">
170 <% =prodQuantity %>
172 VALIGN = "top">
173 $<% =prodTotal %>
187 CLASS = "label">
188 Total:
189

191 $<% =theTotal %>
192

195

196

197

198
199
200
201
202
203
204
210
215
216
UsernamePassword

205 206 NAME = "txtUser" ID = "txtUser"
207 VALUE = "<% =Request( "txtUser" ) %>"
208 CLASS = "typing">
209

211 212 NAME = "txtPass" ID = "txtPass"
213 CLASS = "typing">
214

217

218 219 VALUE = "Submit" CLASS = "button2">
220 221 VALUE = "Cancel" CLASS = "button2">
222 223 VALUE = "<% =storeFrontOrderID %>">
224 225 VALUE = "<% =theTotal %>">
226 227 VALUE = '<% =strCart %>'>
228

229

230
234 SRC = "images/footer.jpg" WIDTH = "750"
235 HEIGHT = "15">

238
239
240
```

```
241 // Exercise 28.4: theItems.js
242 // This file replaces the original theItems.js file
243
244 // Disable/Enable the Add button.
245 function changeAddButton()
246 {
247 if ( isNaN( boxQty.value ) )
248 buyAdd.disabled = true;
249 else {
250 if ( parseInt( boxQty.value ) >= 0 )
251 buyAdd.disabled = false;
252 else
253 buyAdd.disabled = true;
254 }
255 }
256
257 // Buy button pressed
258 function goBuy()
259 {
260 var xmlProduct =
261 xmlShoppingCart.XMLDocument.selectSingleNode(
262 "cart/item[ @isbn = '" + descISBN.innerText + "' ]" );
263
264 var xmlRoot = xmlShoppingCart.XMLDocument.documentElement;
265
266 if ( xmlProduct == null ) {
267 if ( parseInt( boxQty.value, 10 ) <= 0 )
268 return;
269
270 // Product does not exist. Create it.
271 xmlProduct = xmlRoot.appendChild(
272 xmlShoppingCart.XMLDocument.createElement( "item" ) );
273 xmlProduct.setAttribute( "isbn", descISBN.innerText );
274 xmlProduct.setAttribute( "qty",
275 parseInt( boxQty.value, 10 ) );
276
277 fillTable( descISBN.innerText,
278 parseInt( boxQty.value, 10 ) );
279 refreshShoppingTable();
280 }
281 else if ( parseInt( boxQty.value, 10 ) > 0 ) {
282 // Product exits already. Just update.
283 xmlProduct.setAttribute( "isbn", descISBN.innerText );
284 xmlProduct.setAttribute( "qty",
285 parseInt( boxQty.value, 10 ) );
286
287 fillTable( descISBN.innerText,
288 parseInt( boxQty.value, 10 ) );
289 refreshShoppingTable();
290 }
291 else {
292 // Quantity of zero. Remove item from XML.
293
294 xmlRoot.removeChild( xmlProduct );
295 unfillTable( descISBN.innerText );
296 refreshShoppingTable();
297 }
298
299 xmlShoppingCart.save( "storeFrontShoppingCart" );
300
301 if ( xmlRoot.childNodes.length == 0 ) {
302 goCheckOut.disabled = true;
303 goClearShoppingCart.disabled = true;
304 }
305 else {
306 goCheckOut.disabled = false;
307 goClearShoppingCart.disabled = false;
308 }
309 }
310
311 // Checkout button pressed
312 function buyCheckOut()
313 {
314 if ( confirm( "Continue Checkout?" ) == 0 )
315 return;
316
317 // Display the notice.
318 cartWindow.style.display = "none";
319 cartWindow.style.position = "absolute";
320
321 productList.style.display = "none";
322 productList.style.position = "absolute";
323
324 productListing.style.display = "none";
325 productListing.style.position = "absolute";
326
327 noticeShopping.style.display = "block";
328 noticeShopping.style.position = "relative";
329
330 // Set the data
331 form.formXML.value = xmlShoppingCart.XMLDocument.xml;
332
333 // Clear the shopping cart.
334 xmlShoppingCart.XMLDocument.loadXML( "" );
335 xmlShoppingCart.save( "storeFrontShoppingCart" );
336
337 // Submit the form.
338 form.submit();
339 }
```

```
340
341
342
343
344
345
346
347 StoreFront
348
349
351
353
355
357
359
361
363
406
407
408
409

410 411 CELLSPACING = "0" BORDER = "0" BGCOLOR = "#67CDFF"
412 ID = "productList" STYLE = "position: relati

Computer Science & Information Technology

You might also like to view...

Which category of iterators combines the capabilities of input and output iterators into one iterator?

a. Forward iterators. b. Bidirectional iterators. c. Random access iterators. d. Input/output iterators.

Computer Science & Information Technology

Answer the following statements true (T) or false (F)

1. When you write a catch clause, you can optionally assign a name to the exception object. 2. Constant names must always be written in uppercase letters. 3. The keyword const is a qualifier that tells the compiler to make the variable read-only. 4. Buttons are the only controls that respond to Click events.

Computer Science & Information Technology

Which of the following statements is false?.

a. Another common functional-style programming operation is filtering ele-ments to select only those that match a condition. b. Filtering typically produces a list with more elements than the data being filtered. c. To do filtering in a list comprehension, use the if clause. d The following includes in list4 only the even values produced by the for clause: list4 = [item for item in range(1, 11) if item % 2 == 0]

Computer Science & Information Technology

Phones that can use all four bands and three modes and will work with almost any cell phone network in the world are called ________

Fill in the blank(s) with correct word

Computer Science & Information Technology