RE: SOT : Keeping JS Count

2004-08-31 Thread d.a.collie
i would do a full total count on every refresh so you never need to
subtract. 

 
remember and do server side validation tho :)

 
-- 
dc
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




Re: SOT : Keeping JS Count

2004-08-31 Thread Greg Morphis
I can use an onclick to add the count however you can keep clicking on
the radio button to increment it.
onchange only takes effect when you click off of something. 
I suppose I could reverse the values.. give the 1 a value of -1 and
the 0 a value of 1.
Or is it best to loop through the form fields and get a sum each time
something changes?

On Tue, 31 Aug 2004 10:56:52 -0500, Greg Morphis [EMAIL PROTECTED] wrote:
 How do those websites like Dell keep track of price..
 IE
 Say you have 2 radio inputs one with a value of 0, the other with a value of 1.
 And you have five of these..
 a_1 = 0
 a_2 = 1
 a_3 = 0
 a_4 = 0
 a_5 = 1
 how would you keep track of the totals?
 Initially you could just do a sum of the values but what if the user
 changed an option? it wouldnt subtract the 1?
 Any ideas would be appreciated.

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




Re: SOT : Keeping JS Count

2004-08-31 Thread Greg Morphis
so you'd loop through the form fields each time?

On Tue, 31 Aug 2004 11:14:11 -0500, Greg Morphis [EMAIL PROTECTED] wrote:
 I can use an onclick to add the count however you can keep clicking on
 the radio button to increment it.
 onchange only takes effect when you click off of something.
 I suppose I could reverse the values.. give the 1 a value of -1 and
 the 0 a value of 1.
 Or is it best to loop through the form fields and get a sum each time
 something changes?
 
 
 
 On Tue, 31 Aug 2004 10:56:52 -0500, Greg Morphis [EMAIL PROTECTED] wrote:
  How do those websites like Dell keep track of price..
  IE
  Say you have 2 radio inputs one with a value of 0, the other with a value of 1.
  And you have five of these..
  a_1 = 0
  a_2 = 1
  a_3 = 0
  a_4 = 0
  a_5 = 1
  how would you keep track of the totals?
  Initially you could just do a sum of the values but what if the user
  changed an option? it wouldnt subtract the 1?
  Any ideas would be appreciated.
 

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




Re: SOT : Keeping JS Count

2004-08-31 Thread joe velez
If you want the price displayed on the page and updated every time a new option is selected w/o the page being reloaded you need to use _javascript_, otherwise i would imagine the radio button's value would be associated with a price from the database. (optionid 12 = $50)
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




RE: SOT : Keeping JS Count

2004-08-31 Thread d.a.collie
Yeah, count from zero by looping thro the form and totalling every time
that there is an onclick.Then just write that total out in the
apprpriate place.

 
Means that you don't need to bother about keeping track of the state of
the form, means that you are only worried about the current state of the
form when the click happens (as long as that fits into your application)

 
You'd pretty much worked that out in your second email :)

 
-- 
dc
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




Re: SOT : Keeping JS Count

2004-08-31 Thread Greg Morphis
this is what I have
function showValues(theForm) {
currVal = document.getElementById(ptotal);
sum = 0;
for(i=0;itheForm.elements.length - 1;i++) {
sum +=parseInt(theForm.elements[i].value);
}
alert(sum);
}

Unfortunately the radios have a value of 0 and a value of 1. 
So this adds up 0 + 1 per radio and returns 1.
How do I make it add up only whats selected, not both values?
Maybe a radio isnt the right way of doing this? I'm open to any suggestions.

On Tue, 31 Aug 2004 12:27:23 -0400, joe velez
[EMAIL PROTECTED] wrote:
 If you want the price displayed on the page and updated every time a new option is selected w/o the page being reloaded you need to use _javascript_, otherwise i would imagine the radio button's value would be associated with a price from the database. (optionid 12 = $50)
 

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




Re: SOT : Keeping JS Count

2004-08-31 Thread Greg Morphis
I did away with the damn radios and went with select boxes..
that solved the headache! thanks!

On Tue, 31 Aug 2004 17:39:51 +0100, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 Yeah, count from zero by looping thro the form and totalling every time
 that there is an onclick.Then just write that total out in the
 apprpriate place.
 
 Means that you don't need to bother about keeping track of the state of
 the form, means that you are only worried about the current state of the
 form when the click happens (as long as that fits into your application)
 
 You'd pretty much worked that out in your second email :)
 
 --
 dc
 

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




RE: SOT : Keeping JS Count

2004-08-31 Thread Pascal Peters
IS this what you want??

function showValues(theForm) {
var currVal = document.getElementById(ptotal);
var sum = 0;
for(var i=0;itheForm.elements.length;i++) {
if(theForm.elements[i].checked)
 sum +=parseInt(theForm.elements[i].value);
}
alert(sum);
}

Pascal

 -Original Message-
 From: Greg Morphis [mailto:[EMAIL PROTECTED]
 Sent: 31 August 2004 18:34
 To: CF-Talk
 Subject: Re: SOT : Keeping JS Count
 
 this is what I have
 function showValues(theForm) {
currVal = document.getElementById(ptotal);
sum = 0;
for(i=0;itheForm.elements.length - 1;i++) {
 sum +=parseInt(theForm.elements[i].value);
}
alert(sum);
 }
 
 Unfortunately the radios have a value of 0 and a value of 1.
 So this adds up 0 + 1 per radio and returns 1.
 How do I make it add up only whats selected, not both values?
 Maybe a radio isnt the right way of doing this? I'm open to any
 suggestions.

 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]




RE: SOT : Keeping JS Count

2004-08-31 Thread Dave Watts
 Say you have 2 radio inputs one with a value of 0, the other 
 with a value of 1. And you have five of these.. 
 a_1 = 0
 a_2 = 1
 a_3 = 0
 a_4 = 0
 a_5 = 1
 how would you keep track of the totals? 
 Initially you could just do a sum of the values but what if 
 the user changed an option? it wouldnt subtract the 1?
 Any ideas would be appreciated.

You can assign an event handler to any form field, so that when an event
occurs a _javascript_ function is called. For example, if you had an array of
checkboxes, you could loop over them to see which ones were checked. You
could do this whenever any of them were checked or unchecked.

script
function calcTotal() {
	var total = 0;
	for (var i = 0; i  document.forms[0].items.length; i++) {
		if (document.forms[0].items[i].checked) {
			total += document.forms[0].items[i].value;
		}
	}
	document.forms[0].total.value = total;
}
/script

form ...
input type=checkbox name=items value=1  1br
input type=checkbox name=items value=4  4br
input type=text name=total
/form

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
phone: 202-797-5496
fax: 202-797-5444
 [Todays Threads] 
 [This Message] 
 [Subscription] 
 [Fast Unsubscribe] 
 [User Settings]
 [Donations and Support]