treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to incremen the html attribute class using jquery

  • in Zoho Support » Using Zoho Support • 22 hours ago
    How to increment the html attribute class using jquery. i am actually working on a php/ajax data grid. it works on tables and dynamically i am loading rows result from the database. After the user has added rows with results in one table, the user can add new heading and add new rows in new tables. I am using the following code to do this

    var v = jQuery("#frmSovMca").validate({ errorLabelContainer: $("div.msg-error2"),

              submitHandler: function(form) {                       
                  jQuery(form).ajaxSubmit({
                      success: function(response)    {
    
                          obj = jQuery.parseJSON(response);
    
                          if (obj.status == '<?php echo OBJECT_STATUS_SUCCESS; ?>')    {
                              $('#result3').html('<div class="msg msg-thanks">Mca Added/Updated Successfully</div>');
                              setTimeout("$('#result3').html('')", 2000);
                              // $("td.addmca2"+vCounter).html(obj.message);
                              vcounter=<?php $_SESSION['vCounter']; ?>+"";
    
                              if(obj.title==vcounter){
                                  $("td.addmca2").append(obj.message);
    
                                  $("#Gtotal").html(obj.GrandTotal);
                                  $("#Percentage").html(obj.Percentage);
    
                              }else{
                                  $("td.addmca2").html(obj.message);
    
                                  $("#Gtotal").html(obj.GrandTotal);
                                  $("#Percentage").html(obj.Percentage);
    
                              }
    
                          }    else{
                              $('div.msg-error2').html('<div class="msg msg-error">'+obj.error+'</div>');
                              setTimeout("$('div.msg-error2').html('')", 2000);
                          }
    
                      },
                      clearForm:    false,
                      resetForm:    false
                  });
              }
          });
      });
    

    but i cant get the counter variable incremented from php , i need to use it for incrementing the class attribute to insert the new result in new row with the class incremented.

    the php code is here

    $aSovMca = fGetSovMca($vSubID, $sovID, 0, $_SESSION['bidID']);

                      $aSovMca['message'] = fGetScheduleX($aSovMca);
    
    
                      $aSovMca['status'] = OBJECT_STATUS_SUCCESS;
    
                      $vGrandTotal = fGetGrandTotal($_SESSION['bidID']);
                      $vPercentage = fGetPercentage($vGrandTotal);
                      $aSovMca['Percentage'] = $vPercentage;
                      $aSovMca['GrandTotal'] = $vGrandTotal;
    
                      echo json_encode($aSovMca);
    

    function fGetScheduleX($aSovMca) {

      $vList = '
    
    Edit
                  <table border="0" cellpadding="0" cellspacing="0" width="750px">
    
                           <tr height="30">
                                  <td align="left" colspan="5" width="20%" bgcolor="#F8F8F8"  class="simple_bold_blue" style="border:1px solid #D9D9D9;">MCA No.</td>
                                  <td width="30%"  align="left" bgcolor="#F8F8F8"  class="simple_bold_blue blue_border_tbl">MCA Title</td>
                                  <td width="25%" align="left" valign="middle" bgcolor="#F8F8F8"  class="simple_bold_blue blue_border_tbl">Source Quote (CAD)</td>
                                  <td width="10%" align="left" valign="middle" bgcolor="#F8F8F8"  class="simple_bold_blue blue_border_tbl">Your Quote(CAD)</td>
                                  <td width="15%" align="left" valign="middle" bgcolor="#F8F8F8" class="simple_bold_blue blue_border_tbl">
                                  </td>
                              </tr>';
    
      foreach ($aSovMca as $thisVal)
          $vList .= '
    
                              <tr>
                                  <td  width="129" colspan="5" align="left" valign="top" style="font-size:12px;border-left:1px solid #D9D9D9;" class="two_border" >' . $thisVal['McaCode'] . '</td>
                                  <td align="left" valign="top" style="font-size:12px"  class="two_border">' . $thisVal['McaName'] . '</td>
                                  <td align="left" valign="top" style="font-size:12px"  class="two_border">' . $thisVal['YQuoteValue'] . '</td>
                                  <td align="left" valign="top" style="font-size:12px"  class="two_border"></td>
                                  <td align="left" valign="top" style="font-size:12px"  class="two_border"><a class="sidebar" href="javascript:void(0);" onclick="javascript:fEditMcaValue(' . $thisVal['bidSovMcaID'] . ');">Edit</a>&nbsp;|&nbsp;<a class="sidebar" href="javascript:void(0);" onclick="javascript:fConfirmDelete(' . $thisVal['bidSovMcaID'] . ');">Remove</a></td>
                              </tr>
                     ';
    
      $vList .= ' </table><br/>';
    
      return $vList;
    

    }

    this is the html table in which i am appending the db result

    please help me how can i get the soulution out of it please email me the answer at ignitious_php@hotmail.com

  • Your code above is all messy the way you inputted it.

    Please create a Codepen for us to be able to have a look at everything in a clean environment.