You may simply use AJAX to do the calculation without submitting the form
Try searching for AJAX with google
Good luck
Regards
Raj
Main Topics
Browse All TopicsHey Experts!! I hope everyone is having a great holiday weekend.
I have an intranet built on an Access 2003 database and classic ASP. I have been recently been asked to bulid a budgeting system. It consists of something like this:
The accessory table contains the pricing, while the other tables contain the client information as well as the product. The client can have more than one product. However, each product's pricing is set inside the table. So one client could have like 3 products with 3 different accessories. I need to be able to do a budget for up to the next 3 years for one client.
Bottom Line: 1 Client has 3 products with 3 different accessories. I need to do a budget for up to the next 3 years with all 3 products(no pricing) with all 3 accessories per prodcut.
I need to be able to have a form, filled out by the user for quantity and then multiplied by the price to give a total.
I hope I've explained that correctly. I just have NO idea where to start. Nor do I know how to do ASP calculations.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I can provide info and details on AJAX if that is needed but you don't need it if you already planned to submit the form. Please clarify exactly what you need but researching AJAX could be a distraction if I read your question correctly. There are lots of ways to caculate and work with forms and database tables without needing AJAX.
bol
@ b0lsc0tt:
I do apologize for my rambling and complexity of the question. I was looking into AJAX but only found one tutorial(http://www.mikesd
Ultimately, what will happen is the user chooses a client, from there they will go to the budget. From there, they choose quantities (and possibly a discount option) and the number of years. Then boom, it gives them an outlook for the next x amount of years.
Is that a little more understandable? I hope so. :)
Thanks for the response. I do understand what the project entails. I am just not sure exactly what you are asking for here. Keep in mind what I said about project in my first response. What code do you have? What step in this project do you need help with now and in this question?
As far as AJAX goes when the users chooses the client they go to a budget, right? That is on a new page or do you want the page to stay the same? THAT is the key to whether you will need AJAX. From what you said it seems you plan to submit the page when the choose a client and show a new page for what is basically step two. You don't need AJAX for that. There are a lot of great sites for AJAX info, including one of my favorites that even uses ASP (Classic) for the server code. A search of this site's knowledge base for comments by me and words ASP and AJAX should show them to you. You could even open a new question if you want help using or learning AJAX but it doesn't seem like something you need for this project.
Sorry I haven't been able to be specific with the help yet. Let me know if you have a question about this or the general info I provided. If this is something you need all done for you then an EE question won't be the way to get it.
bol
I see what your saying b0lsc0tt. I see that my question is a little confusion. I do apologize for the extended and unnecessary wording. Let's start with this then:
Ultimately, I would like to submit the form because it will ultimately be exported to Excel or PDF.
So how can I perform calculations in classic ASP?
I think this would be best, but I'm not entirely sure. Suggestions?
ASP can handle math calculations with the same math functions that are available to vbscript. There is a good list with simple explanations at http://www.w3schools.com/V
iNum = 5 +3 ' iNum will be 8
iNum = 5 * 3 ' iNum will be 15
Let me know if you have any other questions about caculating in ASP. If you need help with a specific calculation or having problems with a specific one then please provide details.
bol
You still aren't being very specific it seems. Hopefully I have understood you correctly but let me know if it doesn't seem right or give the result you expect. You will need to be more specific on the calculation you need if that is the case.
The snippet below has the code I believe you need. It will mutliply the 3 variables by their prices and add the results. Let me know if you have a question about this or how it works.
bol
I am sorry for badly worded questions. I do appreciate EVERYTHING your helping me with. Let me see if I can explain this now.
I have a form that contains the the named form fields above. These I'm pretty sure are the variables. What I need to do is pass those(as the user submits the form) into the formula that you gave above.
I think the proper question here is, how do you pass user declared variables into an ASP calculation? I have declared the variables. But I want to be able to have the quantities put into the formula(calculation).
Thanks! Your ASP code can get the values from the form fields by using either Request.Form("FIELDNAME") or Request.Querystring("FIELD
Don't forget to validate the form input. You put the value in an ASP variable but should then validate it before trying to use it. In this case since you expect numbers you would check to make sure the input from the form is a number and the type of number you expect. Just a side note or caution but something you should always do. :)
bol
b0lsc0tt you've been very awesome so far. Thanks for everything.
I'll have to get the code later this evening when I get to that PC. I'm off-site right now.
I read what you wrote and it makes sense now. I know the page starts out by declaring my variables like the code below.
How can I get the value of a different recordset inside of that formula? Or should I put this formula inside of the same recordset that pulls all of the data?
I am glad that made sense and helped.
The code in the snippet doesn't mention a recordset so I am not sure what you refer to by "different recordset." The code (or formula) in the snippet just needs to go where you need it. From your earlier post it seems those "qty_" variables and "total" were meant to have info from the form. If that will go in to a database table then you might have the formula (or code above) in the recordset code or right before it. It might even be after. It all matters on the order of the code and its logic. There is no way I can be more specific but hopefully this explanation helps you know how to use it. Just remember the variables only last as long as the script runs and the recordset is something that is opened and closed by the script. You can't do anything with it before or after it is opened/closed.
bol
Here is the entire page of code:
As you can see starting in line 4 is where I want to declare the script and the formulas.
On line 97 I have another recordset that queries all the info I want/need.
Can I put those recordset variables (rs_contact) into my script? Would I have to move my script down the line just after the recordset to achieve this?
The lines in the snippets seem off from what you mention in the response (e.g. line 97 has nothing but ASP open tags). With ~400 lines and since it is DW code it is not easy to get a quick idea of all that is going on.
I did see the recordset called rs_contact. Where in the "script" did you want to use its variables? You will only be able to use them while they exist so if you need that info earlier in the script then you must create the recordset earlier (or twice). If you need the code you have in lines 4-7 (the "script") in the snippet above in the rs_contact area (the "recordset") then you just need to make sure the script is not below the recordset. It could be fine right where it is unless it needs to use info from the recordset. If that is the case it will need to be in the section after rs_contact is made into a recordset.
Does that make sense? Let me know if anything isn't clear or you have a question.
bol
p.s. The lines 4-7, i.e. the "script", needs to have the variable's values set somewhere. If you still need help on this then please clarify if those values come from the form that is submitted or a recordset.
What parts or where are the "calculator" or "user" variables? I think "calculator" is the lines that were in 4-7 in the recent snippet but please confirm or clarify.
Have you moved them somewhere to see what result you get? Did you understand what I meant when I said (a few times I think) the variables have to be defined either before or when you use them? Did you put your formula in the rs_contact recordset? What was the result?
bol
The calculator is lines 4-7. I haven't moved it yet, but what I was thinking was moving into the rs_contact recordset. I think I would put them at the very beginning of the recordset. Right??
But how would I call other fields in that same recordset to interact with that formula?
Unfortunately I won't have any code until maybe tomorrow.
Try what I have already suggested to see how it works and the results you get. Whether you place it in the loop for the recordset, just above that code, or somewhere else usually depends on the result you want (as I have said above). If you aren't sure how it works then try one and the results usually make it clear. If you have a question about using what we have said or its results then let us know and be specific and detailed.
I have no idea what you mean by "other fields" but remember I gave the general information in an earlier comment on how to get form fields. That comment is at http:#a24795127 . It has the info you need to get any value from a submitted form.
Let us know if you have any other questions about what we have said to answer your question here. Remember if other questions come up with this project then it is best to open a new EE question for those.
bol
Ok, did what you said and it works great!! Only problem now is if the page has multiple instances of a product, the total of the first product will go into the total of all the other products even if there isn't a number in the other fields. I am going to open another question.
Just wanted to say thanks for teaching me something new!!
Business Accounts
Answer for Membership
by: b0lsc0ttPosted on 2009-07-02 at 20:30:29ID: 24769616
LZ1,
This won't just be a basic answer if you want all of that. Also to provide info on queries you would use we need details on the fields in each table and any relationships between the tables. If that is all you are really asking for help with then please provide those details. However if you also need the form page made and the report page then will you be doing the main work yourself and just need help with specific issues? Or is this a project you need all done for you? If the latter then it will be best done by hiring a developer in my opinion. If you do just need help with a specific thing and are working on this yourself then please clarify what you need here.
It does sound like an interesting project. Let me know if you have any questions or need more information.
b0lsc0tt