www.webdeveloper.com
Results 1 to 2 of 2

Thread: Form forgets it's seen addition

  1. #1
    Join Date
    May 2013
    Posts
    2

    Form forgets it's seen addition

    Greetings,

    I was not exactly sure how to phrase the title - so there you go. The issue is that I have a script that will add the correct number to the total, but if you choose another button within the radio group, it adds the new number as well as keeping the old number.

    Code:
    function checkTotal(addToTotal, callingName) {
    	addToTotal = parseInt(addToTotal);
    	
    	thisForm = document.forms['makeCremation'][callingName];
    	
    	for (var i = 0; i < thisForm.length - 1; i++) {
    		
    		if(thisForm[i].checked) {
    			sum = sum + parseInt(addToTotal);
    			}
    		}
    		document.makeCremation.theTotal.value = sum.toFixed(2);
    	}
    I then add the following line to the radio buttons:
    onchange="checkTotal('<number I want to add>','<name of the calling radio group>');

    I hope that makes sense. If anyone has any suggestions, please let me know.

    Regards,
    Danny

  2. #2
    Join Date
    May 2013
    Posts
    2
    What I find unusual is that if I call the name specifically instead of using a variable, it works as expected (if I click on another radio button from the same group, it will remove it's previous addition to the total and then add the new total.)

    For example:
    Code:
    function checkTotal(addToTotal, callingName) {
    	addToTotal = parseInt(addToTotal);
    	
    	thisForm = ;
    	
    	for (var i = 0; i < document.forms.makeCremation.nameOfARadioGroup.length - 1; i++) {
    		
    		if(document.forms.makeCremation.nameOfARadioGroup[i].checked) {
    			sum = sum + parseInt(addToTotal);
    			}
    		}
    		document.makeCremation.theTotal.value = sum.toFixed(2);
    	}
    It would seem illogical to have many, many repeating for statements though.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles