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 -

 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 .
JavaScriptjQuery

Avatar of undefined
Last Comment
puneet kumar

8/22/2022 - Mon
Julian Hansen

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.
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.
Julian Hansen

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

I want to know why you want to do that.
Your help has saved me hundreds of hours of internet surfing.
fblack61
puneet kumar

ASKER
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.
Julian Hansen

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.
puneet kumar

ASKER
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 );
    });
});

});

});
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
puneet kumar

ASKER
Thanx a ton for your support.