Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  16] [ 2]  / answers: 1 / hits: 28878  / 12 Years ago, thu, june 14, 2012, 12:00:00

see fiddle
if patient has time slot alloted already then make color yellow using jquery(client side).
in my fiddle if i allot time slot first time then color is green and at the same time when allot
next time slot then previous time slot is grey. i have to make it yellow.
for that i have to find span tag in table and check wheather contains text or not
if contains text then make it yellow.But i m new in jquery.i search lot but not getting.
how can i do that.



//This is button click code



  $(#<%=btnSelect.ClientID%>).click(function ()           {


var cells = $('#tableAppointment tbody tr td:nth-child(3)');


var i = 0;
var topcell = false;

cells.each(function ()
{
var $cell = $(this);

if ($cell.hasClass('csstdhighlight'))
{
if (i == 0)
{
$cell.find('span').text(jQuery('#<%=txtPatientName.ClientID%>').val());
topcell = $cell;
}
else
{
$cell.remove();

}
i++;
}
});
if (topcell && i > 1) topcell.attr('rowspan', i);
$(#tableAppointment tr).each(function ()
{

$('td', this).each(function ()
{
var value = $(this).find(span).val();

if (!value)//i m chking like this
{

}
else
{ //make it yellow
}
})

})

return false;
});
});

More From » jquery

 Answers
26

Instead of this



var value = $(this).find(span).val();


write



var value = $(this).find(span).text();


and if you want to check html inside span then use



var value = $(this).find(span).html();


UPDATE :-



<html><head>
<style>.yell{background:#CCFF00;}.csstd
{
background-color: #ccffcc;
}
table{
background-color: #cccccc;

}</style><script src=jquery.js></script>
<script>var is=false;
$(function(){

$(document).mouseup(function(){is=false;});
$(.csstablelisttd).mousedown(function(e){sen=$(this);
$(.csstd).removeClass(csstd);
$(this).children(:not(:first)).addClass(csstd);
xco=e.clientX;
yco=e.clientY;
is=true;
return false;
});
document.onmousemove=function(){return false;};
$(.csstablelisttd).mouseenter(function(){
if(is){
$(this).children(:not(:first)).addClass(csstd);
if($(.csstd).length>=6){is=false;}
}
});
$(#update).click(function(){
if($(#names).val())
{
$(.csstd).next().hide();

$(.csstd:first).next().show().attr(rowspan,$(.csstd).length/2).children().html($(#names).val());
$(.csstd).removeClass(csstd).addClass(yell);
}
});
});</script></head><body>
<table id=tableAppointment cellspacing=1 width=50% border=1 align=center>
<thead>
<tr class=csstablelisttd>
<td bgcolor=#ffffff>
</td>
<td >
</td>
<td class=csstablelisttd patientName>
<b>Patient Name</b>
</td>
</tr>
</thead>
<tbody>
<tr class=csstablelisttd>
<td valign=top width=70px>
8:00AM
</td>
<td >
0
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
15
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
30
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
45
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td valign=top width=90px>
9:00AM
</td>
<td >
0
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
15
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
30
</td>
<td >
<span></span>
</td>
</tr>
<tr class=csstablelisttd>
<td >
</td>
<td >
45
</td>
<td >
<span></span>
</td>
</tr>
</tbody>
</table>
<input type=text id=names />
<input type=button id=update value=update /> </body></html>

[#84917] Wednesday, June 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;