Here is what i want to do, check the image attached, javascript to sum the values of text boxes in a row having individual total, i have this but not working

  function sum() {
       var txtFirstNumberValue = document.getElementsByName('ca_score[]').value;
       var txtSecondNumberValue = document.getElementsByName('score[]').value;
       if (txtFirstNumberValue == "")
           txtFirstNumberValue = 0;
       if (txtSecondNumberValue == "")
           txtSecondNumberValue = 0;

           for(var i=0;i<txtFirstNumberValue.length;i++) {   

       var result = parseInt(txtFirstNumberValue[i]) + parseInt(txtSecondNumberValue[i]); }
       if (!isNaN(result)) {
           document.getElementsByName('total[]').value = result;
       }
   }

could you post the HTML?

commented: ok...check the thread i just posted it +0
here is the code:

<form name="form1" id="formID" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">

<span class="clearfix"><?php echo $errormess; ?></span>
    <fieldset>

    <table width="75%" border="0" cellpadding="0" style="border-collapse:collapse; height:20px; text-align:left; font-size:12px;" cellspacing="0">

      <tr>
        <td width="20%" style="background-color:#fcfcfc; color:#999; font-weight:bold;">Session:</td>
        <td colspan="3"><?php echo  __getSession(); ?></td>
        </tr>
      <tr>
        <td style="background-color:#fcfcfc; color:#999; font-weight:bold;">Course Code:</td>
        <td width="24%"><?php echo $sys[course_code]; ?></td>
        <td width="21%" style="background-color:#fcfcfc; color:#999; font-weight:bold;">Course Title:</td>
        <td width="35%"><?php $res = __course(); echo $res; ?></td>
      </tr>
      <tr>
        <td style="background-color:#fcfcfc; color:#999; font-weight:bold;">Course Lecturer:</td>
        <td><?php echo $sys[course_lecturer]; ?></td>
        <td style="background-color:#fcfcfc; color:#999; font-weight:bold;">Course Manager:</td>
        <?php @$cm = dbFetchArray( dbQuery("SELECT * FROM tbl_users WHERE user_id='$sys[course_manager]'") ); ?>
        <td><?php echo $cm[user_title]." ".$cm[last_name]." ".$cm[first_name]; ?></td>
      </tr>
    </table>    

    <table width="25%" border="0" cellpadding="0" style="border-collapse:collapse; text-align:left; font-size:12px;" cellspacing="0">
      <tr>
        <td width="8%" style="background-color:#fcfcfc; color:#999; font-weight:bold;">Enrols:</td>
        <td width="3%"><?php echo $num_result; ?></td>
        <td width="5%" style="background-color:#fcfcfc; color:#999; font-weight:bold;">M:</td>
 <?php $countQry = dbFetchArray( dbQuery("SELECT COUNT(*) FROM tbl_stud_registration WHERE stud_gender='Male'")) ?>               
        <td width="3%"><?php echo $countQry['COUNT(*)']; ?></td>
        <td width="5%" style="background-color:#fcfcfc; color:#999; font-weight:bold;">F:</td>
        <td width="76%">&nbsp;</td>
      </tr>
    </table>
    <div class="enroll">
<table cellspacing="0">
  <thead>
        <tr>
       <!-- <th width="">No.</th>  -->
          <th width="9%">Matric. no.</th>
          <th width="29%" class="hide">name</th>
          <th width="6%" class="hide">sex</th>
          <th width="5%" class="hide">age</th>
          <th width="7%">CA</th>
          <th width="10%">Exam score</th>
          <th width="8%">Total</th>
          <th width="26%" class="hide">&nbsp;</th>
        </tr>
      </thead>

      <tbody>
        <tr>
 <?php
//for ($i = 0; $i < $num_result; $i++) {
         while( $row = dbFetchArray($stmQuery)) {
             extract($row);                              

        $query_reg = "SELECT * FROM tbl_stud_registration WHERE stud_id='$stud_id'";
            $resReg = dbFetchArray(dbQuery($query_reg));
             for ( $i = 0 ; $i < dbNumOfRows($stmQuery); $i++)

$checkSc = dbFetchArray(dbQuery("SELECT * FROM tbl_exam_record WHERE stud_id = '$stud_id' AND sess_id='$sessionId'"));
        if($checkSc[cgpa] == 'NULL' || $checkSc[cgpa] == '' || $checkSc[cgpa] == '0') { 

        $editState = ""; 
        $editTitle = ""; 
        $buttonState = ""; }

        else { 
        $editState = 'readonly="readonly"'; 
        $editTitle = "You cannot enter scores again, Result have been published"; 
        $buttonState = 'disabled="disabled"'; }


    //echo ($checkSc[cgpa]);     

?>  

      <!--    <td><?php #echo ($i + 1) ?></td> -->
          <td height="10"><?php echo $resReg[stud_matric] ; ?></td>
          <td class="hide"><?php echo $resReg[stud_Lname]." ".$resReg[stud_Fname]; ?></td>
          <td class="hide"><?php echo $resReg[stud_gender]; ?></td>        
          <td class="hide"><?php echo age($resReg[stud_DoB]); ?></td>
          <td>
<input name="ca_score[]" type="text" class="validate[min[0],max[30],custom[integer]] text-input round" id="val1" style="height:9px;" value="<?php echo $ca_score; ?>" <?php echo $editState; ?> title="<?php echo $editTitle; ?>" onkeyup="sum();" size="1" />
        </td>          
          <td>
<input name="score[]" type="text" class="validate[min[0],max[70],custom[integer]] text-input round center" id="val2" style="height:9px;" value="<?php echo $score; ?>" <?php echo $editState; ?> title="<?php echo $editTitle; ?>" onkeyup="sum();" size="1" />
        </td>
          <td>
<input name="total[]" type="text" class="round text-input" id="total" readonly="readonly" style="height:9px; border:none; background:none;" value="<?php echo $total; ?>" size="1" />
        </td>        
          <td class="hide"><input name="student_id[]" type="hidden" id="student_id" value="<?php echo $stud_id; ?>" /></td>
        </tr>
<?php } ?>
      </tbody>
  </table>
          <div class="clear">&nbsp;</div>
      <div class="float-right">
      <input type="submit" name="Submit" <?php echo $buttonState; ?> class="round blue ic-right-arrow hide" value="Submit" />
      </div>      
    </div>

    </fieldset>

</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.