質問

I'm working on FlexiGrid and having few issue with scripting. I have successfully created a FlexiGrid and added checkbox to it. On checkbox click, i want to selected the desired row. While clicking on any row, it sets the class='trSelected' in <tr id="row101" class="trSelected">. i have tried out some scripting to set it checkbox click, but is not working. Please let me know how to resolve this problem.

<script type="text/javascript"> 
function checkedCall() {
 if( $('#checkNote').is(':checked')){
   //$("#tblflex > tr:first").addClass("trSelected");
   //$(this).parents('tr:first').addClass('trSelected');
   alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
 }else{
  alert('NOTSelected');
  //$("#tblflex > tr:first").removeClass("trSelected");
  //$(this).parents('tr:first').removeClass('trSelected');
 }
}

HTML Code:

<table id="tblflex" class="flexCLS" style="display: table;" border="0">
 <tbody>
  <tr id="row101">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote" onclick="checkedCall();">
    </div>
   </td>
 </tr>
  <tr id="row187">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote" onclick="checkedCall();">
   </div>
 </td>
</tr>

thanks!

役に立ちましたか?

解決

The problem is that all of your checkbox have the same ID "checkNote".

This is a proposed solution

HTML

<table id="tblflex" class="flexCLS" style="display: table;" border="0">
 <tbody>
  <tr id="row101">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote101" onclick="checkedCall(this);">
    </div>
   </td>
 </tr>
  <tr id="row187">
   <td align="left">
    <div style="text-align: left; width: 40px;">
     <input type="checkbox" id="checkNote187" onclick="checkedCall(this);">
   </div>
 </td>
</tr>

And the JS Code

<script type="text/javascript"> 
function checkedCall(this) {
 if( $(this).is(':checked')){
   //$("#tblflex > tr:first").addClass("trSelected");
   //$(this).parents('tr:first').addClass('trSelected');
   alert('Selected' + $(this).parents('tr:first').attr('id')); //unable to find the ID
 }else{
  alert('NOTSelected');
  //$("#tblflex > tr:first").removeClass("trSelected");
  //$(this).parents('tr:first').removeClass('trSelected');
 }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top