Link to home
Start Free TrialLog in
Avatar of puneet kumar
puneet kumar

asked on

in grid view checkbox is Enable while particular row cell is clicked

i have a screen like below -

 User generated image

i have a grid view where 3 date fields are there  along with this each and every row having a checkbox . every row checkbox should be enable when  same row date picker cell is clicked.please let me know if need more clarification .
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

When Date Cell is clicked OR when Date Cell is populated with a date?

Does not make sense as you have described it. If I select a date cell but don't select a date - must the checkbox be selected?
Can the user uncheck the checkbox?

What are you trying to achieve with the checkbox.

What does your code look like - do you have a sample page to show us?

It is not clear what the exact requirements are.
Avatar of puneet kumar
puneet kumar

ASKER

Hi julian please find my code below to create a grid-


<table align=center>

<tr>                  <th>Check/UnCheck</th>
                <th>MYear</th>
                <th>Date1</th>
                <th>Date2</th>
                <th>Date3</th>
</tr>
<%for(int i=0 ; i<mVector.size();i++)
{
      
%>
 <tr>
<td align="top">
<INPUT type="checkbox" class="chkValues" id="ckbCheckAll" name="chkBox" type="checkbox" data-row="row<%=i%>" value="" size="50">
</td>
<td align="left">
<input class="inputText row<%=i%>" type="text" name="mYear" id="mYear"  value="<%=mYearVector.elementAt(i)%>">
</td>

                        <td>
                        <input class="date row<%=i%>" id="pDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(0)==null?"":oldValues.elementAt(0))%>" />
                        </td>
                        <td>
                        <input class="date row<%=i%>" id="qDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(1)==null?"":oldValues.elementAt(1))%>" />
                        </td>
                        <td>
                        <input class="date row<%=i%>" id="iDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(2)==null?"":oldValues.elementAt(2))%>" />
                        </td>

</tr>
<%}%>

</table>



you can easily get that pre populated dates are coming once page load. if i want to change the date
i pick calendar so i want in any row if any calendar date clicked then only that particular row
checkbox is enabled .hope this clarifies you what i need.
checkbox is enabled .hope this clarifies you what i need.
No it doesn't.

I want to know why you want to do that.
Hi Julian,

this i wanted because if i select some date from date picker an checked its working fine
but when we 1st checked then select some date from date picker it gives old values in controller
so that's why we want when some one select some date from date picker then only that particular row
checkbox is enable.
Still not with you.

1. If someone selects the control and enters the SAME date as was there before - what must happen?
2. Can the user uncheck the checkbox?
3. Why can't you simply compare form value to old value to see if it has changed?

I am still not understanding why you need this.
compare old value with new one frankly telling you i don't know how to implement please send some code snippet or example for that thanx in advance and support . java script and jquery i am low  my java script and jsp sample code is below -


<table align=center>

<tr>                  <th>Check/UnCheck</th>
                <th>MYear</th>
                <th>Date1</th>
                <th>Date2</th>
                <th>Date3</th>
</tr>
<%for(int i=0 ; i<mVector.size();i++)
{
     
%>
 <tr>
<td align="top">
<INPUT type="checkbox" class="chkValues" id="ckbCheckAll" name="chkBox" type="checkbox" data-row="row<%=i%>" value="" size="50">
</td>
<td align="left">
<input class="inputText row<%=i%>" type="text" name="mYear" id="mYear"  value="<%=mYearVector.elementAt(i)%>">
</td>

                        <td>
                        <input class="date row<%=i%>" id="pDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(0)==null?"":oldValues.elementAt(0))%>" />
                        </td>
                        <td>
                        <input class="date row<%=i%>" id="qDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(1)==null?"":oldValues.elementAt(1))%>" />
                        </td>
                        <td>
                        <input class="date row<%=i%>" id="iDate<%=i%>" name="dob" type="text" value="<%=(oldValues.elementAt(2)==null?"":oldValues.elementAt(2))%>" />
                        </td>

</tr>
<%}%>

</table>



////////////////////////////////// java script ////////////////////////////////////////////////////


$(document).ready(function(){
       
    $(".date").datepicker();

$('.chkValues').on('click',function(){

 //get values of dates
var array = [];
$row = $(this).data('row');  //row1, row2, row3 etc
$('input.'+$row).each(function() {
    array.push($(this).val());
});
//send array via ajax
//https://api.jquery.com/jquery.ajax/

$("#btnSubmit").click(function (event) {
 
      $.ajax({
    method: "POST",
    url: "DatePicker.jsp",
    data: { array: array}
  })
    .done(function( msg ) {
      alert( "Data Saved: " + msg );
    });
});

});

});
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx a ton for your support.