Help Please

Associate
Joined
6 Jun 2004
Posts
93
Location
London
Thanks for taking a look at this in advance. I have a form in ASP, which writes to an Access Database. In the form there are 3 particular fields, which requires a numerical calculations. This feilds are called Allocation 1 , 2 and 3.

If there is data in only one of the fields COSTCODE then Allocation 1 = 100%. If there is data in 2 COSTCODE feilds then Allocation 1 and Allocation 2 is 50/50 in each Allocation feild, and if there is data in 3rd COSTCODE feild then its 100% divide by 3 = 33.3% in all 3 Allocation feilds. Hope this makes sense!

Cost Code 1 Allocation 1 = 33.3%
Cost Code 2 Allocation 2 = 33.3%
Cost Code 3 Allocation 3 = 33.3%

Total = 100%
 
Id say dozens of people on here would know how to do it, you just havent given us anything to work with really. If you cant provide a link then at least youll have to drop some code in.

So far I see you have three fields, but thats is. When do you want to perform the calculation? As the data is retrieved or on a user action? Where is the info being dispalyed? In a table? Form?

If you take the time to formulate a decent post, it will get answered quickly. No one can be bothered to help if its too much of an efoort.
 
Ok i am really sorry about this guys I am farley new at the whole thing!
Anyways here is another attempt at explaning this!

All three feild should be equally divinded in 100% The information is displayed in the form itself. For example lets say i click on costcode 1 feild in the form. The very next which is allocation 1 would display 100% in it automatically. Then lets say i entered cost code 2 the very next feild called allocation 2 would display 50%, at this point however the first feild allocation 1 for costcode1 would also display 50%.

Let say i entered costcode 1 4444 Allocation 1 = 100%
Then lets say i entered costcode 2 5555 Allocation 2 = 50% and so is Allocation 1!

Basically both feilds are equally divided into 100%. Hope this is clear!
There does not need to be a calculation when someone submits a form, the information is purely for users information.
 
Hope this can explain better





 
you need to upload them to a web server try imageshack http://www.imageshack.us/

I presume that this thread is exactly the same problem but in a different wording to the one that I was trying to help you with? Please could you try spell checking your posts as i for one am finding them difficult, if not impossible to understand.

HT
 
This does what you want to a degree, again Im not 100% on what you are after or how you visioned it working but its a start for you in the couple of minutes its taken me.

This is probably fine if someone only ever does 1, 1 and 2 or 1, 2 and 3 but is there a possibleility they will enter 1 and 3?

This needs to go in each of the costCode input tags markup:
Code:
onchange="calculateAllocation();"
And this in your header:
Code:
<script>
function calculateAllocation()
{
	var intCostCodeCount = 0;
	if(document.getElementById('costCode1').value != '')
	{
		intCostCodeCount ++;
		if(document.getElementById('costCode2').value != '')
		{
			intCostCodeCount ++;
			if(document.getElementById('costCode3').value != '')
				intCostCodeCount ++;
		}
	}
		

	switch(intCostCodeCount)
	{
		case 1 : 
			document.getElementById('allocation1').value = '100%';
			document.getElementById('allocation2').value = '';
			document.getElementById('allocation3').value = '';
			break;
		case 2 : 
			document.getElementById('allocation1').value = '50%';
			document.getElementById('allocation2').value = '50%';
			document.getElementById('allocation3').value = '';
			break;
		case 3 : 
			document.getElementById('allocation1').value = '33.3%';
			document.getElementById('allocation2').value = '33.3%';
			document.getElementById('allocation3').value = '33.3%';
			break;

	}
}
</script>
 
Hi roboffer
Thanks for doing this, I’ll give this a try and let you know how its going!
Once again thanks for all your efforts really appreciate it!
 
Hi roboffer,

I am just writing to say that i've tried this and it works exactly as required! Thanks for all your help. I just wanted to know one more thing which is how do i get the Total feild to add them together as the costcodes are entered in each feild/s.

once again thanks for all your help!
 
Back
Top Bottom