Sum the value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #16
    I mean the code that is generated from your PHP code when you view the source in the browser.

    Comment

    • ddtpmyra
      Contributor
      • Jun 2008
      • 333

      #17
      Originally posted by acoder
      I mean the code that is generated from your PHP code when you view the source in the browser.
      Here it is...
      Code:
      <tr><td width='50%'>Organizations</td><td width='67%'><Input type = 'text' Name ='totalOrganizations'  id ='totalOrganizations' value=''  
          	  onkeyup='if ((document.getElementById('totalOrganizations').match(/^[0-9]+$/) && document.getElementById('totalAgencies').value.match(/^[0-9]+$/)))    
                document.getElementById('Total').value =  parseInt(document.getElementById('totalOrganizations').value)) + parseInt(document.getElementById('TotalAgencies').value);   
                else document.getElementById('Total').value = '';>    
                </td></tr><tr><td>Agencies</td><td width='67%'><Input type = 'text' Name ='totalAgencies' id='totalAgencies' value=''  
        		   	onkeyup='if ((document.getElementById('totalAgencies').match(/^[0-9]+$/) && document.getElementById('totalOrganizations').value.match(/^[0-9]+$/)))    
              	document.getElementById('Total').value =(document.getElementById('totalOrganizations').value) + parseInt(document.getElementById('totalAgencies').value);   
                  else document.getElementById('Total').value = '';>    
                  </td></tr>Grand Total <input type = 'text' value ='' name ='Total' id='Total' >

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #18
        no wonder it doesn’t work, the onkeyup attribute is not closed, resp. it closes at the first JavaScript quotation mark, rendering the HTML invalid.

        my recommendation: use a proper event handler.

        Comment

        • ddtpmyra
          Contributor
          • Jun 2008
          • 333

          #19
          Do you mean by doing this (see onkeyup)
          <Input type = 'text' Name ='totalAgencies ' id='totalAgenci es' value='$row[Total]'
          onkeyup=\"if ((document.getE lementById('tot alAgencies').ma tch(/^[0-9]+$/) && document.getEle mentById('total Organizations') .value.match(/^[0-9]+$/)))
          document.getEle mentById('Total ').value =(document.getE lementById('tot alOrganizations ').value) + parseInt(docume nt.getElementBy Id('totalAgenci es').value);
          else document.getEle mentById('Total ').value = ''\";>

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #20
            well, yes. although IMHO inline JavaScript is bad practice.

            Comment

            • ddtpmyra
              Contributor
              • Jun 2008
              • 333

              #21
              I wonder why it's still not working for me.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #22
                Try this:
                Code:
                <Input type = 'text' Name ='totalAgencies' id='totalAgencies' value='$row[Total]'
                onkeyup='setTotal()'/>
                Code:
                function setTotal() {
                    if ((document.getElementById('totalAgencies').match(/^[0-9]+$/) &&
                      document.getElementById('totalOrganizations').value.match(/^[0-9]+$/))) {
                        document.getElementById('Total').value = 
                          parseInt(document.getElementById('totalOrganizations').value) + 
                          parseInt(document.getElementById('totalAgencies'). value);
                    } else {
                        document.getElementById('Total').value = '';
                    }
                }

                Comment

                Working...