Menu

Add javascript onclick to display column

Help
2008-03-20
2012-10-09
  • naveen namburi

    naveen namburi - 2008-03-20

    hi folks,

    can any one help me,how to call a java script function when i click on a row value in <display:column>,so that i need to retrieve those values and display in to the fields in same jsp.

    Thanks in Advance,
    N.Naveen.

     
    • sahaya

      sahaya - 2008-03-24

      Hi,
      Please try the following script code.
      <td>
      <display:table name="XYZ" id="custTable" pagesize="20" style="width:100%;">
      <display:column property="col1" sortable="true"/>
      <display:column property="col2"/>
      </display:table>

      <script type="text/javascript">highlightTableRows("custTable");</script>
      </td>

      then you can add the following script code in your JS file.

      function highlightTableRows(tableId) {
      var previousClass = null;
      var table = document.getElementById(tableId);
      var tbody = table.getElementsByTagName("tbody")[0];
      var status;
      if (tbody == null) {
      var rows = table.getElementsByTagName("tr");
      } else {
      var rows = tbody.getElementsByTagName("tr");
      }
      // add event handlers so rows light up and are clickable
      for (i=0; i < rows.length; i++) {
      rows[i].onmouseover = function() {
      previousClass=this.className;
      this.className+=' over'
      };
      rows[i].onmouseout = function() {
      this.className=previousClass
      };
      rows[i].onclick = function() {
      var cell = this.getElementsByTagName("td")[0];
      var cell1 = this.getElementsByTagName("td")[1];
      var col1Value = cell.innerHTML;
      var col2Value = cell1.innerHTML;
      << here u can place this value to your fields for ex:>>
      document.forms[0].field1.value= col1Value;
      document.forms[0].field1.value= col2Value;
      }
      }
      }

      Cheers,
      Sahaya ANTONI

       
      • naveen namburi

        naveen namburi - 2008-03-24

        Hi Sahaya,

        In your mail you mentioned like "<script type="text/javascript">highlightTableRows("custTable");</script> ", can you please tell me how to call this "highlightTableRows("custTable");" when click on a row value.

        Thanks And Regards,
        N.Naveen.

         
    • naveen namburi

      naveen namburi - 2008-03-24

      Hi Sahaya,

      Thanks iam able to call the function and display my values,but i need some more help, In some scenarios iam not displaying all the column values but i wan't to get all the values of that corresponding row when i click a particular row.

      Help Appreciated.

      Thanks And Regards,
      N.Naveen.

       

Log in to post a comment.