radio or checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #46
    not necessarily, you can define buttons using <button>, or you can write your script in a way, that it doesn’t matter. you may not even require a button.

    Comment

    • colinod
      Contributor
      • Nov 2007
      • 347

      #47
      could i script it so if you clicked on a radio that is selected it would set it as unselected

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #48
        yes, you can.

        Comment

        • colinod
          Contributor
          • Nov 2007
          • 347

          #49
          ok

          My calculations are set with this code

          Code:
          function calculate(f)
          {
          var nums = f.num;
          var ntext = f.num;
          var result = 0;
          for(var i=0;i<nums.length;i++)
          {
          if(nums[i].checked)
          {
          result+=parseFloat(ntext[i].value);
          }
          }
          f.answer.value=Number(result).toFixed(2);
          will a click event change this?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #50
            before I answer that … make an educated guess.

            hint: check your event handlers

            Comment

            • colinod
              Contributor
              • Nov 2007
              • 347

              #51
              Not sure what you mean and then realised the page i was editing somehow had and old calculation on it and now the page will not add the totals using the calculation a was using?

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #52
                confused

                Comment

                • colinod
                  Contributor
                  • Nov 2007
                  • 347

                  #53
                  Finally sorted the site out, dont know what happened there but i now have the following for my calculations

                  Code:
                  function UpdateCost() {
                    var sum = runtotal;
                    var gn, elem;
                    for (i=0; i<205; i++) {
                      gn = 'id'+i;
                      elem = document.getElementById(gn);
                      if (elem.checked == true) { sum += Number(elem.value); }
                    }
                     parseFloat(sum);
                    document.getElementById('total').value = sum.toFixed(2);
                  What i was thinking was could i have another function something like this

                  Code:
                  function check() {
                    var gn, elem;
                    for (i=0; i<205; i++) {
                      gn = 'id'+i;
                      elem = document.getElementById(gn);
                      if (elem.checked == true) 
                  then
                  elem.checked == false
                  
                  else elemchecked==true
                    }
                  then call my calculate funtion
                  }
                  this is probably way too complicated and i know it wont work

                  Comment

                  • colinod
                    Contributor
                    • Nov 2007
                    • 347

                    #54
                    i seem to be getting there, i now have the following called by double click and this unchecks 1 radio and removes from the total, what i cant figure out is how to get this in a function that works on a single click

                    Code:
                    function checkbutt(i) 
                    {
                    	var gn;
                    	gn = 'id'+i;
                    	{
                        document.getElementById(gn).checked = false;
                    	}
                    	UpdateCost();
                    }

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #55
                      note: parseFloat(sum) ; (line #9) still does nothing.

                      Comment

                      Working...