• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read the respective row when a check box checked  RSS feed

 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am displaying the bean values as:

<tr class="<%=styleClass%>" >
<td height="18"> <input type = "checkbox" value=<%=aerNo%>></td>
<td height="18"> <%=aer_no%></td>
<td height="18"> <%=selectVersionNo%></td>
<td height="18"> <%=latestVersionNo%></td>
</tr>


Here all the rows will be created dynamically.

I want to read the corresponding row which are all the checkbox's checked in that time of submit.

In the array checkedValue I have the values of corresponding checked check box values.

for(var j=0;j<checkedValue.length;j++)
{
alert(checkedValue[j]+" "+checkedValue.length+" aer_no :"+aer_no );
if(checkedValue[j]==aer_no)
{
alert("From if.........");
// var latestValue = objCols.item(2).innerText;
//alert("valueToUpdate :"+valueToUpdate);
}
}

Even though if I have the matches value in the abouve if condition its not entering in to that if block.
Please give me idea to read this corresponding row.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you wrote aer_no and aerno. Is this a typo ?
 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
you wrote aer_no and aerno. Is this a typo ?


hi aer_no is second columns value. like
var aer_no = objCols.item(1).innerText;

i am assigining the <%=aerNo%> as unique value into that value of checkbox
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with checkedValue[j].value
 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
Try with checkedValue[j].value


Hi eventhough if I try using checkedValue[j].value I am not getting the value and able to match the both values.
Thank you
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the information displayed in the alert ok ?
 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the first alert
alert(checkedValue[j]+" "+checkedValue.length+" aer_no :"+aer_no );

is displaying correct value but not entering in to the if condition:
if(checkedValue[j]==aer_no)

If I put the checkedValue[j].value I am getting as undefined in the alert
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me know how did you form or get checkedValue array? is it is a array of values of checkboxes or array of check box html controls.

Which browser are you trying use?
You need to access array by formal item method like


instead of array[i], though array[i] should also work.

I think this has to be moved HTML and Javascript forum.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is checkedValue. Wouldn't you need a name for the checkbox?
 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for reply.

checkvalue will contains the which are all the check box's I have checked.
the full code for read which I wrote is :

mybody=document.getElementsByTagName("body").item(0);
mytab=document.getElementById("mytable");
var objRows=mytab.getElementsByTagName("tr");
var noOfRows=mytab.getElementsByTagName("tr").length;
var valueToUpdate = "";
var checkedValue = new Array();
var j=0;
for(var i=0;i<document.SelectLatest.elements.length;i++)
{
if(document.SelectLatest.elements[i].type == 'checkbox' && document.SelectLatest.elements[i].checked == true)
{
checkedValue[j] = document.SelectLatest.elements[i].value;
j=j+1;
}
}

alert("checkedValue Length :"+checkedValue.length);
for(var i=0;i<noOfRows;i++)
{
var objCols=objRows[i].getElementsByTagName("td");
var aer_no = objCols.item(1).innerText;
alert("value "+objCols.item(0).checked);
for(var j=0;j<checkedValue.length;j++)
{
var checkedValue_t = checkedValue[j];
alert(checkedValue[j]+" "+" aer_no :"+aer_no );
if(checkedValue[j]==aer_no)
{
alert("From if.........");
}
}
}
 
Manesh Kumar
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kapildev ganeshan:
thank you for reply.

checkvalue will contains the which are all the check box's I have checked.
the full code for read which I wrote is :

mybody=document.getElementsByTagName("body").item(0);
mytab=document.getElementById("mytable");
var objRows=mytab.getElementsByTagName("tr");
var noOfRows=mytab.getElementsByTagName("tr").length;
var valueToUpdate = "";
var checkedValue = new Array();
var j=0;
for(var i=0;i<document.SelectLatest.elements.length;i++)
{
if(document.SelectLatest.elements[i].type == 'checkbox' && document.SelectLatest.elements[i].checked == true)
{
checkedValue[j] = document.SelectLatest.elements[i].value;
j=j+1;
}
}

alert("checkedValue Length :"+checkedValue.length);
for(var i=0;i<noOfRows;i++)
{
var objCols=objRows[i].getElementsByTagName("td");
var aer_no = objCols.item(1).innerText;
alert("value "+objCols.item(0).checked);
for(var j=0;j<checkedValue.length;j++)
{
var checkedValue_t = checkedValue[j];
alert(checkedValue[j]+" "+" aer_no :"+aer_no );
if(checkedValue[j]==aer_no)
{
alert("From if.........");
}
}
}




Is aerNo and aer_no contains same values?

If not, then how come checkedValue[j] and aer_no cane be compared.


I think you want, all selected checkboxes corresponding values (labels)?
Then you should not compare checkedValue[j]==aer_no. You need to get he checkbox control for each row and compare its values with checked values. If it matches then you can call objCols.item(1).innerText.


Hope this helps.
 
kapildev ganeshan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i done like following way. Its working.
thankyou

<%
String test=aer_no+"~"+lVer+"#"+svalue;
%>
<td height="18"> <input type = "checkbox" value=<%=test%>></td>

in script


mybody=document.getElementsByTagName("body").item(0);
mytab=document.getElementById("mytable");
var objRows=mytab.getElementsByTagName("tr");
var noOfRows=mytab.getElementsByTagName("tr").length;
var valueToUpdate = "";
var checkedValue = new Array();
var j=0;
var value="";
for(var i=0;i<document.SelectLatest.elements.length;i++)
{
if(document.SelectLatest.elements[i].type == 'checkbox' && document.SelectLatest.elements[i].checked == true)
{
value = value + document.SelectLatest.elements[i].value+";"
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!