Radio Button Value Calculation. The forth choice will not sum - javascript

Fellas,
I have a javscript that calculates values defined in radio buttons. For a reason I can not figure out why the script skips a group. Its seems that the skipped group (by skipped I mean the selected value does not get added) correlates with the amount of radio buttons being used in each group.
I have been pulling my hair out on this one..
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function setRadios()
{
function sumRadios(){
var total = 0, i = 0, oForm = this.form, e, len, j, c;
while(e=oForm.elements[i++]){
//This is probably the issue - Maybe it would be easier to manually define the names verses detecting them incrementally.
if(e.name.match(/^m4j-\d/)){
c=document.getElementsByName(e.name);
for(j=0;j<c.length;j++){
c[j].checked?total+=Number(c[j].value):null;
i++;
}
}
}
// Defines the field that totals the selections
oForm.elements['m4j-65'].value = total.toFixed(0);
}
// Must define form name "m4jFrom"
var i = 0, input, inputs = document.getElementById('m4jForm').getElementsByTagName('input');
while (input = inputs.item(i++))
// This executes the sum onclick
if (input.name.match(/^m4j-\d/))
input.onclick = sumRadios;
}
onload = setRadios;
</script>
<style type="text/css"></style>
</head>
<body>
<form id="m4jForm" name="m4jForm" method="post" enctype="multipart/form-data" action="">
<table border="0" align="left" cellpadding="11" cellspacing="11" class="m4j_form_table">
<tbody>
<tr id="m4je-57" >
<td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
<tbody>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-57-0" name="m4j-57" value="1" >
</input> 1 </td>
</tr>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-57-1" name="m4j-57" value="2" >
</input>
2 </td>
</tr>
</tbody>
</table></td>
</tr>
<tr id="m4je-61" >
<td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
<tbody>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-61-0" name="m4j-62" value="1" >
</input>
1 </td>
</tr>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-61-1" name="m4j-62" value="2" >
</input>
2 </td>
</tr>
</tbody>
</table></td>
</tr>
<tr id="m4je-62" >
<td colspan="2" align="left" valign="top"><table border="3" style="width: 100%;" >
<tbody>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-62-0" name="m4j-63" value="1" >
</input>
1 No Calculation </td>
</tr>
<tr>
<td align="left" valign="top"><input class="m4jRadio" type="radio" id="m4j-62-1" name="m4j-63" value="2" >
</input>
2 if you remove this table the non calculation will move to the radios below</td>
</tr>
</tbody>
</table></td>
</tr>
<tr id="m4je-63" >
<td colspan="2" align="left" valign="top"><table border="1" style="width: 100%;" >
<tbody>
<tr>
<td align="left" valign="top"><div class="m4jSelectItem m4jSelectItemVertical">
<input class="m4jRadio" type="radio" id="m4j-63-0" name="m4j-64" value="1" >
</input>
1 </div></td>
</tr>
<tr>
<td align="left" valign="top"><div class="m4jSelectItem m4jSelectItemVertical">
<input class="m4jRadio" type="radio" id="m4j-63-1" name="m4j-64" value="2" >
</input>
2 </div></td>
</tr>
</tbody>
</table>
</div>
</div></td>
</tr>
<tr id="m4je-65" >
<td width="300" align="left" valign="top" >Total</td>
<td width="0px;" align="left" valign="top" >
<input class="m4jInputField" style="width: 100%;" id="m4j-65" name="m4j-65" type="text" size="18" maxlength="60" value= "" alt="" ></input><br>
<input type="submit" name="submit" value="send" class ="m4j_submit" >
</input>
<input id="m4jResetButton" class ="m4j_reset" type="reset" name="reset" value="reset">
</input>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

I found the solution. I owe the board the info. I hope someone gets use out of it. :)
<script type="text/javascript">
function setRadios()
{
var inputs = document.getElementById('m4jForm').getElementsByClassName('m4jRadio');
function sumRadios(){
var total = 0,
oForm = this.form;
for(var x = 0; x < inputs.length; x++){
if (inputs[x].checked) total += parseInt(inputs[x].value);
}
// Defines the field that totals the selections
oForm.elements['m4j-65'].value = total.toFixed(0);
}
for(var y = 0; y < inputs.length; y++){
inputs[y].onclick = sumRadios;
}
}
onload = setRadios;
</script>

Related

Loan Calculator Javascript Code Issue?

I am creating a loan calculator for my website with Javascript Code and the website is https://www.usawebcash.com/missouri-installment-loans. I am getting issues with the coding of this loan calculator in Javascript. I want help for this code and the code is following:
<script language="JavaScript">
<!--
function showpay() {
if ((document.calc.loan.value == null || document.calc.loan.value.length == 0) ||
(document.calc.months.value == null || document.calc.months.value.length == 0) ||
(document.calc.rate.value == null || document.calc.rate.value.length == 0)) {
document.calc.pay.value = "Incomplete data";
} else {
var princ = document.calc.loan.value
var term = document.calc.months.value
var intr = document.calc.rate.value / 1200
document.calc.pay.value = princ * intr / (1 - (Math.pow(1 / (1 + intr), term)));
}
// payment = principle * monthly interest/(1 - (1/(1+Interest of Month)*Months))
}
// -->
</script>
Calculate button. Clicking the Reset button will clear all values
<p>
<center>
<form name=calc method=POST>
<table width=60% border=0>
<tr>
<th bgcolor="#aaaaaa" width=50%><font color=blue>Description</font>
</th>
<tr bgcolor="#aaaaaa" width=50%><font color=blue>Data Entry</font>
</th>
</tr>
<tr>
<td bgcolor="#eeeee">Loan Amount</td>
<td bgcolor="#aaeeaa" align=right>
<input type=text name=loan size=10>
</td>
</tr>
<tr>
<td bgcolor="#eeeee">Loan Length in Months</td>
<td bgcolor="#aaeeaa" align=right>
<input type=text name=months size=10>
</td>
</tr>
<tr>
<td bgcolor="#eeeee">Interest Rate</td>
<td bgcolor="#aaeeaa" align=right>
<input type=text name=rate size=10>
</td>
</tr>
<tr>
<td bgcolor="#eeeee">Monthly Payment</td>
<td bgcolor="#eeaaaa" align=right><em>Calculated</em>
<input type=text name=pay size=10>
</td>
</tr>
<tr>
<td bgcolor="#aaeeaa" align=center>
<input type=button onClick='showpay()' value=Calculate>
</td>
<td bgcolor="#eeeeaa" align=center>
<input type=reset value=Reset>
</td>
</tr>
</table>
</form>
<font size=1>Enter only numeric values <br>
Non-numeric values will cause errors are not allowed
<p align="center"><font face="arial" size="-2">This free script provided by</font>
<br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font>
</p>

Unable to dynamically calculate an input value onchange

I have been trying to get this calculator to work in my WordPress blog but haven't been successful at it.
I did get simple Hello world pop-up to work but not this. I want to calculate the "BPodds". Can you guys tell me what's wrong with this?
function calcStake() {
var BWodds = document.getElementById('BWodds').value;
var div = document.getElementById('div').value;
var BPodds = ((BWodds - 1) / div) + 1;
document.getElementById('BPodds').innerHTML = BPodds;
}
<table class="table" border="0" width="500" cellspacing="1" cellpadding="3">
<tbody>
<tr class="calcheading">
<td colspan="3"><strong>Each Way Lay Calculator</strong>
</td>
</tr>
<tr class="calchead">
<td align="center">Bookmaker Win odds:</td>
<td align="center">Place divider:</td>
<td align="center">Bookmaker Place odds:</td>
</tr>
<tr class="calcrow">
<td align="center">
<input id="BWodds" type="text" value="10" onchange="calcStake()" />
</td>
<td align="center">
<input id="div" type="text" value="4" onchange="calcStake()" />
</td>
<td align="center">
<input id="BPodds" />
</td>
</tr>
</tbody>
</table>
You should use value instead of innerHtml:
document.getElementById('BPodds').value = BPodds;
Here is the fiddle: http://jsfiddle.net/o5ze12mf/
The problem is not with Wordpress,
You are trying to put the result in INPUT with innerHTML but to change the value of INPUT you need to use .value
You code will be like this :
<script type="text/javascript">
function calcStake() {
var BWodds = document.getElementById('BWodds').value;
var div = document.getElementById('div').value;
var BPodds = ((BWodds - 1) / div) + 1;
document.getElementById('BPodds').value = BPodds;
}
</script>
<table class="table" border="0" width="500" cellspacing="1" cellpadding="3">
<tbody>
<tr class="calcheading">
<td colspan="3"><strong>Each Way Lay Calculator</strong></td>
</tr>
<tr class="calchead">
<td align="center">Bookmaker Win odds:</td>
<td align="center">Place divider:</td>
<td align="center">Bookmaker Place odds:</td>
</tr>
<tr class="calcrow">
<td align="center">
<input id="BWodds" type="text" value="10" onchange="calcStake()" />
</td>
<td align="center">
<input id="div" type="text" value="4" onchange="calcStake()" />
</td>
<td align="center">
<input id="BPodds" />
</td>
</tr>
</tbody>
</table>
I just changed
document.getElementById('BPodds').innerHTML = BPodds;
to
document.getElementById('BPodds').value = BPodds;

Jquery isn't setting radio button

I'm trying to have "set all" radio buttons at the bottom of my popup control so when the user has a long list of conflicts to resolve, they can just select one of the radio buttons and the option will be quickly select. However, my javascript fires, and seems to find the radio button, but fails to actually set the radio button.
I have a gridview gvErrors that is being looped though and in the second cell of each gridview row is a table with the options (tblOptions). I have tried using .attr("checked", true), .setAttribute("checked", true), and .prop("checked", true). I am receiving no errors, in the console, but the radio buttons all remain unchecked. Any help with this would be appreciated. Below is the Javascript.
<script type="text/javascript" language="javascript">
function selectAll(option) {
var grid = document.getElementById("<%=gvErrors.ClientID%>");
for (var i = 0; i < grid.rows.length; i++)
{
var row = grid.rows[i];
var table = $(row).find("tblOptions");
var radio = $(table).find("input[name*=" + option + "]:radio");
//$('td input:radiobutton', '#tblOptions').prop('checked', true);
$(radio).prop("checked", "checked");
var test = "";
}
};
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
//This handles the rows or colums selection
$("#<%=rdbCancelAll.ClientID%>").click(function() {
selectAll("rdbCancel");
});
});
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
//This handles the rows or colums selection
$("#<%=rdbReplaceAll.ClientID%>").click(function() {
selectAll("rdbReplace");
});
});
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
//This handles the rows or colums selection
$("#<%=rdbRenameAll.ClientID%>").click(function() {
selectAll("rdbRename");
});
});
</script>
Small example of the gridview:
<table class="tableinfo nocollapse c6" cellspacing="1" cellpadding="2" border="0" id="ctl00_Main_gvErrors">
<tbody>
<tr class="tableinfobody tableinfoGray">
<th scope="col"><span class="c1">Current Name</span></th>
<th scope="col"><span class="c1">Options</span></th>
<th scope="col">Differences</th>
</tr>
<tr class="tableinfobody">
<td class="l"><span id="ctl00_Main_gvErrors_ctl02_lblName">Test1</span></td>
<td class="l">
<table id="ctl00_Main_gvErrors_ctl02_tblOptions" border="0">
<tbody>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl02_rdbCancel" type="radio" name=
"ctl00$Main$gvErrors$ctl02$Options" value="rdbCancel" /><label for=
"ctl00_Main_gvErrors_ctl02_rdbCancel">Cancel adding signal.</label></td>
</tr>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl02_rdbReplace" type="radio" name=
"ctl00$Main$gvErrors$ctl02$Options" value="rdbReplace" /><label for=
"ctl00_Main_gvErrors_ctl02_rdbReplace">Replace curent signal with
imported signal.</label></td>
</tr>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl02_rdbRename" type="radio" name=
"ctl00$Main$gvErrors$ctl02$Options" value="rdbRename" /><label for=
"ctl00_Main_gvErrors_ctl02_rdbRename">Rename imported signal to:</label>
<input name="ctl00$Main$gvErrors$ctl02$txtNewName" type="text" value=
"Test1_1" id="ctl00_Main_gvErrors_ctl02_txtNewName" class="c2" /></td>
</tr>
</tbody>
</table>
</td>
<td class="l">
<input type="hidden" name="ctl00$Main$gvErrors$ctl02$hfParamInternalUnmatched"
id="ctl00_Main_gvErrors_ctl02_hfParamInternalUnmatched" value=
"EBC1-Test1" /> <input type="hidden" name=
"ctl00$Main$gvErrors$ctl02$hfParamInternalMatched" id=
"ctl00_Main_gvErrors_ctl02_hfParamInternalMatched" value="Test1" />
<table class="tableinfo c5" cellspacing="1" cellpadding="2" border="0">
<tbody>
<tr class="tableinfobody tableinfoGray">
<th>Value Name</th>
<th>Current</th>
<th>Imported</th>
</tr>
<tr class="tableinfobody">
<td class="c3">Unit</td>
<td class="c4"></td>
<td class="c4">flag</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="tableinfobody tableinfoGray">
<td class="l"><span id="ctl00_Main_gvErrors_ctl03_lblName">Test2</span></td>
<td class="l">
<table id="ctl00_Main_gvErrors_ctl03_tblOptions" border="0">
<tbody>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl03_rdbCancel" type="radio" name=
"ctl00$Main$gvErrors$ctl03$Options" value="rdbCancel" /><label for=
"ctl00_Main_gvErrors_ctl03_rdbCancel">Cancel adding signal.</label></td>
</tr>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl03_rdbReplace" type="radio" name=
"ctl00$Main$gvErrors$ctl03$Options" value="rdbReplace" /><label for=
"ctl00_Main_gvErrors_ctl03_rdbReplace">Replace curent signal with
imported signal.</label></td>
</tr>
<tr>
<td><input id="ctl00_Main_gvErrors_ctl03_rdbRename" type="radio" name=
"ctl00$Main$gvErrors$ctl03$Options" value="rdbRename" /><label for=
"ctl00_Main_gvErrors_ctl03_rdbRename">Rename imported signal to:</label>
<input name="ctl00$Main$gvErrors$ctl03$txtNewName" type="text" value=
"Test2_1" id="ctl00_Main_gvErrors_ctl03_txtNewName" class="c2" /></td>
</tr>
</tbody>
</table>
</td>
<td class="l">
<input type="hidden" name="ctl00$Main$gvErrors$ctl03$hfParamInternalUnmatched"
id="ctl00_Main_gvErrors_ctl03_hfParamInternalUnmatched" value=
"HCMData3-Testw" /> <input type="hidden" name=
"ctl00$Main$gvErrors$ctl03$hfParamInternalMatched" id=
"ctl00_Main_gvErrors_ctl03_hfParamInternalMatched" value=
"PrimaryData3-Testw" />
<table class="tableinfo c5" cellspacing="1" cellpadding="2" border="0">
<tbody>
<tr class="tableinfobody tableinfoGray">
<th>Value Name</th>
<th>Current</th>
<th>Imported</th>
</tr>
<tr class="tableinfobody">
<td class="c3">SA</td>
<td class="c4">3, 239</td>
<td class="c4">239</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr class="tableinfobody tableinfoBlue">
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
Any help clearing this up would be greatly appreciated.
Use the value as a selector like so
function selectAll(option) {
var radio = $("input[value=" + option + "]");
$(radio).prop("checked", "checked");
}
$('input[type="button"]').on('click', function(){
var value = $(this).data('attr');
selectAll(value);
});
http://jsfiddle.net/3u3z4bLn/3/

Make the JavaScript link hide onClick

I have a form page and certain items only appear on the list if a link is clicked on. I want the link to hide when it is clicked on and the action it calls un-hides.
This is my test page:
function toggle_it(itemID) {
// Toggle visibility between none and ''
if ((document.getElementById(itemID).style.display == 'none')) {
document.getElementById(itemID).style.display = ''
event.preventDefault()
} else {
document.getElementById(itemID).style.display = 'none';
event.preventDefault()
}
}
<table width="500" border="1" cellpadding="3">
<cfform action="" method="POST">
<tr>
<td align="center"><strong>ID</strong>
</td>
<td align="center"><strong>DESCRIPTION</strong>
</td>
<td align="center">
<strong>SAY IT</strong>
</td>
</tr>
<tr>
<td align="center">a</td>
<td>
The field with no name
</td>
<td>
<cfinput type="Text" name="aaa" value="">
</td>
</tr>
<tr id="tr1" style="display:none">
<td align="center">a1</td>
<td>Add-on1</td>
<td>
<cfinput type="Text" name="a1" value="Add-on1">
</td>
</tr>
<tr id="tr2" style="display:none">
<td align="center">a2</td>
<td>Add-on2</td>
<td>
<cfinput type="Text" name="a2" value="Add-on2">
</td>
</tr>
<tr id="tr3" style="display:none">
<td align="center">a3</td>
<td>Add-on - Daily1</td>
<td>
<cfinput type="Text" name="a1d" value="Add-on - Daily1">
</td>
</tr>
<tr id="tr4" style="display:none">
<td align="center">a4</td>
<td>Add-on - Daily2</td>
<td>
<cfinput type="Text" name="a2d" value="Add-on - Daily2">
</td>
</tr>
<tr>
<td colspan=3>
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</cfform>
</table>
<!--- ----------------------------------------------------------------- --->
<table border="0">
<tr>
<td align="right">Add-on1: </td>
<td>Add-on1
</td>
</tr>
<tr>
<td align="right">Add-on2: </td>
<td>Add-on2
</td>
</tr>
<tr>
<td align="right">Add-on3 - Daily1: </td>
<td>Add-on - Daily1
</td>
</tr>
<tr>
<td align="right">Add-on4 - Daily2: </td>
<td>Add-on - Daily2
</td>
</tr>
</table>
The code is in CF but this is a JavaScript function.
BTW. Thank you whoever wrote the original script I found on Stackoverflow a while back.
Plunker
Description: Gave html elements for toggle unique ids. Also needed to update the javascript to get the parent element of the parent element of the link clicked. This only works when there are two elements to reach the tr.
Importantly, this code has an extra unhide that isn't needed...since we are hiding it and there is nothing to click.
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<table width="500" border="1" cellpadding="3">
<cfform action="" method="POST">
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>DESCRIPTION</strong></td>
<td align="center">
<strong>SAY IT</strong>
</td>
</tr>
<tr>
<td align="center">a</td>
<td>
The field with no name
</td>
<td>
<cfinput type="Text" name="aaa" value="">
</td>
</tr>
<tr id="tr1" style="display:none">
<td align="center">a1</td>
<td>Add-on1</td>
<td>
<cfinput type="Text" name="a1" value="Add-on1">
</td>
</tr>
<tr id="tr2" style="display:none">
<td align="center">a2</td>
<td>Add-on2</td>
<td>
<cfinput type="Text" name="a2" value="Add-on2">
</td>
</tr>
<tr id="tr3" style="display:none">
<td align="center">a3</td>
<td>Add-on - Daily1</td>
<td>
<cfinput type="Text" name="a1d" value="Add-on - Daily1">
</td>
</tr>
<tr id="tr4" style="display:none">
<td align="center">a4</td>
<td>Add-on - Daily2</td>
<td>
<cfinput type="Text" name="a2d" value="Add-on - Daily2">
</td>
</tr>
<tr>
<td colspan=3>
<input type="submit" name="Submit" value="Submit"></td>
</tr>
</cfform>
</table>
<!--- ----------------------------------------------------------------- --->
<table border="0">
<tr>
<td align="right">Add-on1: </td>
<td>Add-on1</td>
</tr>
<tr>
<td align="right">Add-on2: </td>
<td>Add-on2</td>
</tr>
<tr>
<td align="right">Add-on3 - Daily1: </td>
<td>Add-on - Daily1</td>
</tr>
<tr>
<td align="right">Add-on4 - Daily2: </td>
<td>Add-on - Daily2</td>
</tr>
</table>
</body>
</html>
JS
// Code goes here
function toggle_it(itemClickedID, itemID) {
// Toggle visibility between none and ''
if ((document.getElementById(itemID).style.display == 'none')) {
document.getElementById(itemID).style.display = '';
//gets the parent element of the parent element which is the row
document.getElementById(itemClickedID).parentElement.parentElement.style.display = 'none';
event.preventDefault();
} else {
event.preventDefault();
//gets the parent element of the parent element which is the row
document.getElementById(itemClickedID).parentElement.parentElement.style.display = '';
document.getElementById(itemID).style.display = 'none';
}
}

Select/Deselect All Checkboxes along with colour changing of a selected row using jquery

I have a table where each row has some data and the user can submit all rows or single row or some rows. So, every row has a checkbox now and If the user checks the checkbox the background colour of this row should be changed(I have implemented this using jquery). Now there is another checkbox to select All these checkboxes, I have implemented this too with jquery. Now the issue is that when I selectAll checkboxes the row background-colour doesnot change , but when I check individual rows it gets changed. Being a novice coder I can understand that click event is not happening so the background colour is not changing. So I have used change event instead of click , but it's still the same. The functions for select All and row background colour change are working good but individually. Need help regarding this...
Thanks in advance,
NoviceCoder.
Without any of your code I tried something. See if you can apply to your code. (working example)
HTML
<table>
<thead>
<tr>
<th><input type="checkbox" name="selectAll" id="selectAll" /></th>
<th>Row name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="select" /></td>
<td>test row 0</td>
</tr>
<tr>
<td><input type="checkbox" name="select" /></td>
<td>test row 1</td>
</tr>
<tr>
<td><input type="checkbox" name="select" /></td>
<td>test row 2</td>
</tr>
<tr>
<td><input type="checkbox" name="select" /></td>
<td>test row 3</td>
</tr>
<tr>
<td><input type="checkbox" name="select" /></td>
<td>test row 4</td>
</tr>
</tbody>
</table>
CSS
.selected { background-color: #ffff00; }
Javascript
jQuery(function($) {
$('tbody :checkbox').change(function() {
$(this).closest('tr').toggleClass('selected', this.checked);
});
$('thead :checkbox').change(function() {
$('tbody :checkbox').prop('checked', this.checked).trigger('change');
});
});
this is a simple example for your request just copy/paste all this code, in new page and run it. Enjoy
<html>
<head>
<title>How to highlight the selected row in table/gridview using jquery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"
charset="utf-8"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$("#checkall").live('click',function(event){
$('input:checkbox:not(#checkall)').attr('checked',this.checked);
//To Highlight
if ($(this).attr("checked") == true)
{
//$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#FF3700");
$("#tblDisplay").find('tr:not(#chkrow)').css("background-color","#FC9A01");
}
else
{
//$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#fff");
$("#tblDisplay").find('tr:not(#chkrow)').css("background-color","#FFF");
}
});
$('input:checkbox:not(#checkall)').live('click',function(event)
{
if($("#checkall").attr('checked') == true && this.checked == false)
{
$("#checkall").attr('checked',false);
$(this).closest('tr').css("background-color","#ffffff");
}
if(this.checked == true)
{
$(this).closest('tr').css("background-color","#FC9A01");
CheckSelectAll();
}
if(this.checked == false)
{
$(this).closest('tr').css("background-color","#ffffff");
}
});
function CheckSelectAll()
{
var flag = true;
$('input:checkbox:not(#checkall)').each(function() {
if(this.checked == false)
flag = false;
});
$("#checkall").attr('checked',flag);
}
});
</script>
</head>
<body>
<table width="50%" cellspacing="0" border="0" align="left" id="tblDisplay" cellpading="0"
style="font-family: verdana; font-size: 10px;">
<thead>
<tr id="chkrow">
<th>
<input type="checkbox" id="checkall" />
</th>
<th>
Sr.
</th>
<th style="text-align: left;">
First Name
</th>
<th style="text-align: left;">
Last Name
</th>
<th>
Country
</th>
<th>
Marital Status
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">
<input type="checkbox" value="1" />
</td>
<td style="text-align: center;">
1
</td>
<td style="text-align: left;">
Adeel
</td>
<td style="text-align: left;">
Fakhar
</td>
<td style="text-align: center;">
Pakistan
</td>
<td style="text-align: center;">
Single
</td>
</tr>
<tr>
<td style="text-align: center;">
<input type="checkbox" value="2" />
</td>
<td style="text-align: center;">
2
</td>
<td style="text-align: left;">
Omer
</td>
<td style="text-align: left;">
Fakhar
</td>
<td style="text-align: center;">
Pakistan
</td>
<td style="text-align: center;">
Single
</td>
</tr>
<tr>
<td style="text-align: center;">
<input type="checkbox" value="3" />
</td>
<td style="text-align: center;">
3
</td>
<td style="text-align: left;">
Umer
</td>
<td style="text-align: left;">
Mukhtar
</td>
<td style="text-align: center;">
Pakistan
</td>
<td style="text-align: center;">
Single
</td>
</tr>
<tr>
<td style="text-align: center;">
<input type="checkbox" value="4" />
</td>
<td style="text-align: center;">
4
</td>
<td style="text-align: left;">
Mark
</td>
<td style="text-align: left;">
Waugh
</td>
<td style="text-align: center;">
Australia
</td>
<td style="text-align: center;">
Married
</td>
</tr>
</tbody>
</table>
</body>
</html>

Categories

Resources