ASP.NET - Jquery - Asked By Justin Deva on 04-May-12 05:36 AM

Earn up to 20 extra points for answering this tough question.


  JavaScript for getting the value of dynamic created adjacent cells of selected image Of A cell....
  Stuck With This....Help Pls....

 THis is My Click evennt Script..

  <script type="text/javascript" language="javascript">

function Booked(thil,id,ctrl)

{

var imgPath = new String();

imgPath = document.getElementById('ctl00_ContentPlaceHolder1_'+ctrl).style.backgroundImage;

 

 

 

// var chkt=document.getElementById('ContentPlaceHolder1_'+ctrl);

var lbl = document.getElementById('<%=lblseat.ClientID %>');

var amt = document.getElementById('<%=lblamt.ClientID %>');

var amtval = 0;

amtval = document.getElementById('<%= price.ClientID %>');

 

var amount = 0;

// if(chkt.checked==false)

//{

 

//}

if(imgPath == 'url("../images/A.jpg")' || imgPath == 'url(../images/A.jpg)')

{

imgName = "../images/NA.jpg";

 

document.getElementById('ctl00_ContentPlaceHolder1_'+ctrl).style.background = "url(" + imgName + ")";

 

if(lbl.innerHTML == "")

{

lbl.innerHTML = id;

}

else if(lbl.innerHTML != "")

{

lbl.innerHTML = lbl.innerHTML + "," + id;

}

 

if(amt.innerHTML == "")

{

amount =0;

}

else

{

amount = parseInt(amt.innerHTML);

}

 

amtval = parseInt(amount) + parseInt(amtval.value);

}

 

else if(imgPath == "url(../images/NA.jpg)" || imgPath == 'url("../images/NA.jpg")')

{

imgName = "../images/A.jpg";

document.getElementById('ctl00_ContentPlaceHolder1_'+ctrl).style.background = "url(" + imgName + ")";

var rep = id+",";

var rep1 = id;

lbl.innerHTML = lbl.innerHTML.replace(rep,"");

lbl.innerHTML = lbl.innerHTML.replace(rep1,"");

 

if(lbl.innerHTML.endsWith(","))

{

var count = lbl.innerHTML.length;

 

if(lbl.innerHTML.indexOf(','))

{

lbl.innerHTML = lbl.innerHTML.substring(0,count-1);

}

}

 

if(amt.innerHTML == "")

{

amount =0;

}

else

{

amount = parseInt(amt.innerHTML);

}

 

amtval = parseInt(amount) - parseInt(amtval.value);

}

 

 

amt.innerHTML = amtval.toString();

document.getElementById("<%=seatno.ClientID %>").value = lbl.innerHTML;

document.getElementById("<%=totalamount.ClientID %>").value = amtval;

}

}

 

</script>

 

[)ia6l0 iii replied to Justin Deva on 04-May-12 09:44 PM
Which line throws error? And what is the error?

However, at a glance, I have few recommendations. 

a) If you are using ASP.Net 4.0, use the ClientIdMode property of the web server control , and set it to a value like static. That will avoid you figuring out elements on the DOM using run time generated id's. You can then stick to the id's what you provide.
document.getElementById('ctl00_ContentPlaceHolder1_'+ctrl).style.backgroundImage;  

var lbl = document.getElementById('<%=lblseat.ClientID %>');


b) There is an unused parameter in your funciton called "thil". What did you intend to use this for? If it was a typo and you intended "this" - that would be more helpful. 

Hope this helps.
Jitendra Faye replied to Justin Deva on 07-May-12 01:04 AM
YOu can get dynamic cell by following ways.

First you need to assign id for that cell while creating cell, after that use this code to get cell-

document
.getElementById("id").value

Second can assign any css class so that you can access like this-

var cell= $(".classname");