...

View Full Version : JavaScript for calculation from two database generated drop-down lists.



wisdomt
09-22-2005, 12:39 PM
I want to perform a "real-time" calculation on two prices contained within two drop-down list selection in some ASP/SQL code for our intranet site.

Basically, I have two drop-list price lists (A and B), with each price list being stored in a separate SQL database (ID, Description, Price).

When both price lists have a valid selection, I want to display the price B - A within the form.

I have got it working by refreshing the form using an "onchange" event, but this is messy and is causing problems elsewhere, I would love to get it working without having to keep refreshing the page, using JavaScript which is not my strongest skill, and not getting very far.

Any help very welcome.

The code for one of the drop-list lists is:

<select name="DesignerPriceList">
<option value=0></option>
<% sqlstr = "SELECT ID, Description, Price FROM TxDesignPriceList WHERE Designer=" & DesignerID & " ORDER BY Description"
rs2.Open sqlstr, conn
While Not rs2.EOF %>
<option value=<%=rs2("ID")%><%If int(DesignerPriceList) = rs2("ID") Then%> SELECTED <%End If%>><%=rs2("Description")%> / <%=rs2("Price")%></option>
<% rs2.MoveNext
Wend
rs2.Close %>
</select>

Regards,

Steve

rm-f
09-22-2005, 02:16 PM
Breaking object persistence?

I have got it working by refreshing the form using an "onchange" event, but this is messy and is causing problems elsewhere

xmlHttpRequest

would love to get it working without having to keep refreshing the page

data - business logic - presentation
try not to cross 3-tier rules (separate BL from presentation)

wisdomt
09-22-2005, 02:54 PM
Breaking object persistence?


xmlHttpRequest


data - business logic - presentation
try not to cross 3-tier rules (separate BL from presentation)


and in English?


Sorry don't understand.

rm-f
09-22-2005, 04:06 PM
data - business logic - presentation
try not to cross 3-tier rules (separate BL from presentation)
You should separate Business Logic (BL) layer from Presentation layer. Do not change session and persistent data in the Presentation layer directly, but send an update request to the BL layer. Otherwise you can run very easy into problems (you have described them as "but this is messy and is causing problems elsewhere").

M$ recommends to see ASP as part of Presentation layer not as BL layer. BL should be encapsulated in components that are used by ASP.


xmlHttpRequest
This is answer to the: "get it working without having to keep refreshing the page". By using xmlHttpRequest you can send data back and forth without "refreshing the page".

wisdomt
09-22-2005, 04:53 PM
You should separate Business Logic (BL) layer from Presentation layer. Do not change session and persistent data in the Presentation layer directly, but send an update request to the BL layer. Otherwise you can run very easy into problems (you have described them as "but this is messy and is causing problems elsewhere").

M$ recommends to see ASP as part of Presentation layer not as BL layer. BL should be encapsulated in components that are used by ASP.


This is answer to the: "get it working without having to keep refreshing the page". By using xmlHttpRequest you can send data back and forth without "refreshing the page".

Thanks rm-f,

I have been researching and playing with xmlHttpRequest and have got it working on a similar feature that I wanted (ie. in a form, select a name from a drop-down list, and get their address and phone number automatically displayed). Works like a dream, and I will now be using this "feature" a lot now. Now going to work on my price-list calculation.....

Thank you again rm-f for introducing me to this cool feature.

Still must admit that although I understand what you are saying about separate layers, don't have any idea how to implement this in asp/javascript.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum