Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First Attempt at Calculating in ASP

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi All,

I'm sure some out there will solve this in an instant...or tell me it can't be done.

I'm building a registration form with a number of options and I would like the price of each option to appear one the user has selected, or deselected the option.

I have made an attempt at it, but I'm flying blind here. Below is an example of what I am after.
Code:
'A checkbox witha value set to "Full" when Checked
<input name="ChkFullCong" type="checkbox" id="ChkFullCong" value="Full" onClick="ConfAll" ></td>
              <td height="24" valign="bottom" bgcolor="#66FF66" class="text">
			  $ 
			  <%
			  Function ConfAll
			   Dim ConfFull
			  ConfFull =""
			  If ChkFullCong = "Full" Then
			  ConfFull = ConfFull +	cboConsession ' a select box with a numerical value
			  Else
			  ConfFull = ConfFull & "0"
			  End If
			  Response.Write ConfFull 
			  End Function
			  %>

Once I have this for each option, i would like to place a "calculate button, or the like at the bottom that adds all of the options up"

So where Am I going wrong, or what do I need to do? maybe point me to some example code that will see me on the right track?

Thanks in advance

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Thanks for that,

Does tell me a whole lot though. I'd appreciate some assistance here.

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Server-side code is only responsible for making a file and sending it to the end-user (in most cases an HTML file). Once it has rendered the page and sent it out to be viewed in the end-users browser, the script is done. Additionally there is no way to directly call a server-side ASP function from a client-side input.
In this situation your options are:
POST/GET the form back to the server (which then would allow you to execute or re-execute an ASP page from scratch)
Use an XMLHTTP control to POST/GET/Request content from a server-side ASP page
Use a client-side function to calculate the total.

-T

Best MS KB Ever:
 
Tarwn,

Thanks for the more in depth explanation. I do understand the server side and client side situation.

It still does not solve my issue. Chris has pointed me toward the JavaScript forums to get an answer. Which I am looking at now.

Chris, thank you for the suggestion, I will have a play with some of the code posted here to see if it works for me. If I'm still having problems, I may end up taking this problem there... unless there is a way of creating client side calculations in ASP???

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
The clue is in the name... ASP = Active SERVER Pages. As already explained ASP acts on the server and produces an output which is sent to the client - all the ASP processing is finished and closed before the page is sent to the client. Your choices (as already described):
1. Use Javascript to process the data clientside
2. Use POST or GET (either to get a new ASP page to process the input and serve another page) or use XMLHTTP via AJAX

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
OK Guys,

Bit slow on the uptake, but I get the picture. Will look at Java or XMLHTTP. Any ideas on which is easier?

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
you will have to look at some javascript. ( not java or XMLHTTP -> for handling XML and 'scraping' other external pages)

ok..

so if you have 3 check boxes, you will need to have mixture of BOTH ASP and Javascript. ASP to populate the identities that can be fed to the Javascript.

this should give you point in the right direction.(I'm not going to give full answer, cos where is the fun in that! :) )

Code:
<script language="javascript>
function ConfALL(id, Text)
{
if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

</script>
'A checkbox witha value set to "Full" when Checked
<input name="ChkFullCong" type="checkbox" id="ChkFullCong" value="Full" onClick="ConfAll(<%= id%>, <% text%>)" ></td>
              <td height="24" valign="bottom" bgcolor="#66FF66" class="text">
            <div id="1">
            .... Text GOES in HERE....
            </div>
            </td>

This be able to handle most browsers..

that javascript is simply copied from another site..

as people said Google is you friend, but find the right search criteria is tricky if you don't really know what you want to achieve.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top