We help IT Professionals succeed at work.

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

puneet kumar
puneet kumar asked
on
i have a screen like below -

 Requirement.png

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 .
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
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.

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
checkbox is enabled .hope this clarifies you what i need.
No it doesn't.

I want to know why you want to do that.

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
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.

Author

Commented:
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 );
    });
});

});

});
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
1. Please use code tags when posting code
  - highlight your code
  - Click the CODE button

Makes it much easier to read your posts.

2. I am going to list my questions again. Can you answer them so we can move forward.

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?

Author

Commented:
Thanx a ton for your support.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.