Jquery change text ajax request problem - php

I have an html file as coded below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.style1 {
background-color: #c3d9ff;
font-family:arial,sans-serif;
}
.style2 {
text-align: center;
font-weight: bold;
}
.style3 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: center;
font-weight: bold;
}
.style4 {
background-color: #FFFFFF;
font-family:arial,sans-serif;
text-align: left;
}
body {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:15px;
background-color: ;
}
.action_button {
font-weight:bold;
float:right;
}
</style>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript">$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Activate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Inactivate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
</script>
</head>
<body>
<table style="width: 90%" align="center" class="style1">
<tr>
<td colspan="7" class="style2">MANAGER</td>
</tr>
<tr>
<td class="style3" style="width: 139px">Col1</td>
<td class="style3" style="width: 139px">Col2</td>
<td class="style3" style="width: 139px">Col3</td>
<td class="style3" style="width: 139px">Col4</td>
<td class="style3" style="width: 139px">Col5</td>
<td class="style3" style="width: 200px">Col6</td>
<td class="style3" style="">Action</td>
</tr>
</table>
<td id="main" class="main">
<td class="update">
<table style="width: 90%" align="center" class="style1">
<tr>
<td class="style4" style="width: 139px">DataA1</td>
<td class="style4" style="width: 139px">DataA2</td>
<td class="style4" style="width: 139px">DataA3</td>
<td class="style4" style="width: 139px">DataA4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataA6</td>
<td>
<button href="#" id="DataA1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataB1</td>
<td class="style4" style="width: 139px">DataB2</td>
<td class="style4" style="width: 139px">DataB3</td>
<td class="style4" style="width: 139px">DataB4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataB6</td>
<td>
<button href="#" id="DataB1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataC1</td>
<td class="style4" style="width: 139px">DataC2</td>
<td class="style4" style="width: 139px">DataC3</td>
<td class="style4" style="width: 139px">DataC4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataC6</td>
<td>
<button href="#" id="DataC1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataD1</td>
<td class="style4" style="width: 139px">DataD2</td>
<td class="style4" style="width: 139px">DataD3</td>
<td class="style4" style="width: 139px">DataD4</td>
<td class="style4 clickme2" style="width: 139px">Active</td>
<td class="style4" style="width: 200px">DataD6</td>
<td>
<button href="#" id="DataD1" class="action_button" style="width:80px;height:">
Inactivate</button>
</td>
</tr>
<tr>
<td class="style4" style="width: 139px">DataE1</td>
<td class="style4" style="width: 139px">DataE2</td>
<td class="style4" style="width: 139px">DataE3</td>
<td class="style4" style="width: 139px">DataE4</td>
<td class="style4 clickme2" style="width: 139px">Inactive</td>
<td class="style4" style="width: 200px">DataE6</td>
<td>
<button href="#" id="DataE1" class="action_button" style="width:80px;height:">
Activate</button>
</td>
</tr>
</table>
</td>
</td>
</body>
</html>
The fage contain a table with 5 rows with a button at the end of the row. On click, the button submits data to a php file and then changes text and blurs according to the response from php file. The blur function and change text function in col5 is working well. But the change text function in button got really buggy. The button text should change accordingly. the text of button "Activate" should change to "Inactivate" and the text of button "Inactivate" should change to "Activate" on click / successful submission.. This is not working..
Below is the php file code
<?php
$id = $_POST[id];
if($id=="DataA1"){
echo "ACTIVATED";
}
if($id=="DataB1"){
echo "ACTIVATED";
}
if($id=="DataE1"){
echo "ACTIVATED";
}
if($id=="DataC1"){
echo "INACTIVATED";
}
if($id=="DataD1"){
echo "INACTIVATED";
}
?>
Thanks in advance.. :)
blasteralfred

I think your logic is wrong. When the button initially says "Activate", you are returning "ACTIVATED" so your button should then read "Inactivate." You are, however, setting the text to "Activate" again. Look at the button with id "DataA1" for an example.

Change $_POST[id] to $_POST["id"].

I found the solution..
Thank you #Heikki, #Cristy..... :)
I corrected the script as below
$(function() {
$('.action_button').click(function() {
var $button = $(this);
$.ajax({
type: 'POST',
url: 'action.php',
data: 'id='+ $(this).attr('id'),
cache: false,
success: function(result) {
var $row = $button.closest('tr');
var $col = $row.find('.clickme2');
$row.fadeOut('fast', function() {
if (result == 'ACTIVATED') {
$button.text('Inactivate');
$col.text('Active');
} else if (result == 'INACTIVATED') {
$button.text('Activate');
$col.text('Inactive');
}
}).fadeIn();
}
});
return false;
});
});
Thanks again ... :)

I know you've already solved the problem, but here's my answear anyway:
Replace
data: 'id='+ $(this).attr('id'),
with
data: 'val='+ $button.html(),
And, the php file with this:
<?php
$val = $_POST['val'];
if(strstr($val,"Activate"))
echo "ACTIVATED";
else
echo "INACTIVATED";
?>

Related

Passing input type file through ajax

So I am trying to pass a file through Ajax along with other data in the form. Every data except the file is getting passed. I am sending an email with all the data using php. I am new to Ajax and tried many ways. But still not sure where I am going wrong.
So here is my jQuery code
$(document).ready(function(){
$("#submitbtn").click(function(){
var uname = $("#uname").val();
var uemail= $("#uemail").val();
var subject= $("#subject").val();
var resume= $('input[type=file]').val();
var message= $("#message").val();
if(uname == '')
{
$("#errormsgs1").html("Please Enter Name");
$("#uname").css("border","1px solid #f00");
$("#uname").focus();
return false;
}
if(uemail == '')
{
$("#errormsgs2").html("Please Enter Email");
$("#uemail").css("border","1px solid #f00");
$("#uemail").focus();
return false;
}
if(subject == '')
{
$("#errormsgs3").html("Please Enter Subject");
$("#subject").css("border","1px solid #f00");
$("#subject").focus();
return false;
}
if(resume == '')
{
$("#errormsgs4").html("Please Enter Your Resume");
$("#resume").css("border","1px solid #f00");
$("#resume").focus();
return false;
}
if(message == '')
{
$("#errormsgs5").html("Please Enter Message");
$("#message").css("border","1px solid #f00");
$("#message").focus();
return false;
}
$("form#data").submit(function(){
var formData = new FormData(this);
$.ajax({
url: mycareer.php,
type: 'POST',
data: formData,
async: false,
success: function (data) {
alert(data)
},
cache: false,
contentType: false,
processData: false
});
return false;
});
Below is the mycareer.php file
<?php
$uname = $_POST['uname'];
print_r($uname);
$uemail = $_POST['uemail'];
print_r($uemail);
//$subject = $_POST['subject'];
$resume = $_FILES['resume'];
print_r($resume );
$message = $_POST['message'];
print_r($message );
if($uname !='' && $uemail !='')
{
$to = 'sayantan.m#gmail.in';
$subject = "My Career";
$message ='<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Mycareer.in</title>
<style type="text/css">
div, p, a, li, td {
-webkit-text-size-adjust:none;
}
.ReadMsgBody {
width: 100%;
background-color: #d1d1d1;
}
.ExternalClass {
width: 100%;
background-color: #d1d1d1;
line-height:100%;
}
body {
width: 100%;
height: 100%;
background-color: #d1d1d1;
margin:0;
padding:0;
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust:100%;
}
html {
width: 100%;
}
img {
-ms-interpolation-mode:bicubic;
}
table[class=full] {
padding:0 !important;
border:none !important;
}
table td img[class=imgresponsive] {
width:100% !important;
height:auto !important;
display:block !important;
}
#media only screen and (max-width: 800px) {
body {
width:auto!important;
}
table[class=full] {
width:100%!important;
}
table[class=devicewidth] {
width:100% !important;
padding-left:20px !important;
padding-right: 20px!important;
}
table td img.responsiveimg {
width:100% !important;
height:auto !important;
display:block !important;
}
}
#media only screen and (max-width: 640px) {
table[class=devicewidth] {
width:100% !important;
}
table[class=inner] {
width:100%!important;
text-align: center!important;
clear: both;
}
table td a[class=top-button] {
width:160px !important;
font-size:14px !important;
line-height:37px !important;
}
table td[class=readmore-button] {
text-align:center !important;
}
table td[class=readmore-button] a {
float:none !important;
display:inline-block !important;
}
.hide {
display:none !important;
}
table td[class=smallfont] {
border:none !important;
font-size:26px !important;
}
table td[class=sidespace] {
width:10px !important;
}
}
#media only screen and (max-width: 520px) {
}
#media only screen and (max-width: 480px) {
table {
border-collapse: collapse;
}
table td[class=template-img] img {
width:100% !important;
display:block !important;
}
}
#media only screen and (max-width: 320px) {
}
</style>
</head>
<body style="background:#f2f2f2;">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td height="54"> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="border-radius:5px 5px 0 0; background-color:#ffffff;">
<tr>
<td height="29"> </td>
</tr>
<tr>
<td><table border="0" cellspacing="0" cellpadding="0" align="left" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td width="23" class="hide"> </td>
<td height="75" class="inner" valign="middle"><img class="logo" src="http://my.in/img/my-logo.png" width="180" height="61" alt="Logo" style="background: #000;padding: 10px;"></td>
</tr>
</table>
<table width="150" border="0" cellspacing="0" cellpadding="0" align="right" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td height="15"> </td>
</tr>
<tr>
<td align="center">View online</td>
<td class="hide" width="20"> </td>
</tr>
</table></td>
</tr>
<tr>
<td style="border-bottom:1px solid #dbdbdb;"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="background-color:#ffffff;">
<tr>
<td height="23"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="23" class="sidespace"> </td>
<td><table width="76%" border="0" cellspacing="0" cellpadding="0" align="left" class="inner" id="banner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<!--<tr>
<td style="font:bold 20px Arial, Helvetica, sans-serif; border-right:1px solid #dbdbdb;color: #000;" class="smallfont">THE BEST NUTRITION PLANS ARE HERE</td>
</tr>-->
<tr>
<td height="20"> </td>
</tr>
</table>
<!--<table width="22%" border="0" cellspacing="0" cellpadding="0" align="right" class="inner" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt;">
<tr>
<td align="center"><img src="http://www.quanutrition.com/images/facebook.png" width="32" height="atuo" alt="Social Media" /></td>
<td align="center"><img src="http://www.quanutrition.com/images/twitter.png" width="32" height="atuo" alt="Social Media" /></td>
<td align="center"><img src="http://www.quanutrition.com/images/google.png" width="32" height="atuo" alt="Social Media" /></td>
</tr>
<tr>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
</tr>
</table>--></td>
<td width="23" class="sidespace"> </td>
</tr>
</table>
<!--<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="3.33%" class="sidespace"> </td>
<td width="93.33%"><img class="imgresponsive" src="http://www.quanutrition.com/images/banner1.jpg" width="554" height="atuo" alt="Banner" /></td>
<td width="3.33%" class="sidespace"> </td>
</tr>
<tr>
<td height="20"> </td>
<td height="20"> </td>
<td height="20"> </td>
</tr>
</table>-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="23" class="sidespace"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="left" class="inner">
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;width: 20%;color: #000;" class="smallfont">Name </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$uname.'</td>
</tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Email </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$uemail.'</td>
</tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Mobile </td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$resume.'</td>
</tr>
<tr>
<tr>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont">Message:</td>
<td style="font:15px/19px Arial, Helvetica, sans-serif;padding-bottom: 8px;color: #000;" class="smallfont" width="23">'.$message.'</td>
</tr>
<tr>
<td height="20"> </td>
<td class="hide" height="20"> </td>
</tr>
</table>
</td>
<td width="23" class="sidespace"> </td>
</tr>
<tr>
<td height="16"> </td>
<td height="16"> </td>
<td height="16"> </td>
</tr>
</table></td>
</tr>
<tr>
<td style="border-bottom:1px solid #dbdbdb;"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td align="center"><table width="600" border="0" cellspacing="0" cellpadding="0" align="center" class="devicewidth">
<tr>
<td><table width="100%" bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0" align="center" class="full" style="border-radius:0 0 7px 7px;">
<tr>
<td height="18"> </td>
</tr>
<tr>
<td><table class="inner" align="right" width="340" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; text-align:center;">
<tr>
<td width="21"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="full">
<tr>
<td height="18"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<table class="inner" align="left" width="230" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; text-align:center;">
<tr>
<td width="21"> </td>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" style="font:11px Helvetica, Arial, sans-serif; color:#000000;">© 2017, All rights reserved </td>
</tr>
<tr>
<td height="18"> </td>
</tr>
</table></td>
<td width="21"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="20"> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: mail#my.in' . "\r\n";
$headers .= 'Reply-to: '.$uemail.'' . "\r\n";
//$headers .= 'Cc: rajendra.b#my.in' . "\r\n";
$sent = mail($to,$subject,$message,$headers);
echo "Thankyou for Contacting with us. We will get back you soon !!.";
}
else
{
echo "Please enter all the fields.";
}
?>
Below is the form
<form action="purpledotcareer.php" id="fileUploadForm" method="post" enctype="multipart/form-data" onsubmit="return checkvalidate()">
<div class="form-group">
<label for="email">Enter Your Name:</label>
<input type="text" class="form-control" id="uname" name="uname" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" type="text" value="" >
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" id="uemail" name="uemail" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" type="text" value="" >
</div>
<div class="form-group">
<label for="email">Message:</label>
<textarea class="form-control" id="message" name="message" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" rows="3" ></textarea>
</div>
<div class="form-group">
<label for="email">Upload Resume:</label>
<input type="file" class="form-control" id="resume" name="resume" onblur="if (this.value == '') {this.value = '';}" onfocus="this.value = '';" required="" accept=".xlsx,.xls,.doc, .docx,.ppt, .pptx,.txt,.pdf" >
</div>
<button type="submit" id="btnSubmit" class="btn btn-default">Submit</button>
</form>
It will be really helpful if anybody can solve this. Thanks in advance

php form cannot submit which access by ajax

I try to submit form using isset($_POST(['submit'])) in php file which access through ajax but it doesn't work. Please find the code snippets below:
<html>
<script>
$(document).ready(function() {
$.ajax({
url: './B.php',
type: 'POST',
success: function(data)
{ $("#showB").html(data);}
});
});
</script>
<body>
<table style="width: 100%">
<tr>
<td colspan="2"><div id="showB"></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
B.php:
<html>
<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
$message= "halo";
}
?>
<head>
<title>Untitled 1</title>
</head>
<body>
<table>
<tr>
<td style="height: 30px"></td>
<td style="height: 30px"><?php if(!empty($message)) { echo $message; } ?></td>
<td style="height: 30px"></td>
<td style="height: 30px; width: 298px;"></td>
</tr>
<form method="post" action="halo.php">
<tr>
<td> </td>
<td>
<input name="submit" type="submit" value="Save Changes"/></td>
<td> </td>
<td style="width: 298px">
</td>
</tr>
<tr>
<td style="width: 244px; height: 26px;"><h5>Effective Width : </h5></td>
<td style="width: 262px; height: 26px;"><input name="effectivewidth" type="text"/></td>
<td style="width: 261px; height: 26px;"></td>
<td style="width: 298px; height: 26px;"></td>
</tr>
</form>
</table>
</body>
</html>
The form in B.php cannot be submit with no error. Please help. thanks
Its because you are not passing any data over post.
<script>
$(document).ready(function() {
$.ajax({
url: './B.php',
type: 'POST',
data: { submit: "submit"},
success: function(data)
{ $("#showB").html(data);}
});
});
</script>
Pass the appropriate data to $.ajax
https://api.jquery.com/jQuery.ajax/

Unable to pass value from a row to another page in AJAX

I have a table with 7 columns(Complaintid id,name,school name etc...) and also have a button. When I click the button I need to pass the complaintid of that row to another page. The problem is that value is not passing in the ajax page.
<html>
<body>
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php echo $ row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button" id="'<?php $button; ?>'" onclick="selectedjob(alert('hi there')<?php $job_id ?>)">
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
<input type='hidden' value='view' class='button' name="selectedjob" id="selectedjob">
</table>
</form>
<script type="text/javascript">
function selectjob(jobid)
{
$('#selectedjob').val(jobid);
$('#frmSelectJob').attr('action', 'careers-apply.php');
$('#frmSelectJob').attr('method', 'post');
$('#frmSelectJob').submit();
}
</body>
</html>
Try this. You need to echo
<input type="button" value="View" class="button" id="'<?php echo $button; ?>'" onclick="selectedjob(<?php echo $job_id; ?>)">
EDIT
You can pass the jobid as like this
function selectjob(jobid)
{
window.location.href = "display.php?jobid=" + jobid;
}
get the job id in display.php as $_GET['jobid']
You can do it by using jquery. I write simple code for you. I try it. It should work
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" >
jQuery(document).ready(function(){
<?php
// $num_rows=mysql_num_rows(query result)
$num_rows=10;
for($i=1;$i<$num_rows+1;$i++)
{
?>
$("#button_<?=$i?>").click(function(){
//alert("hi");
var complain_Id = $("#complain_Id_<?=$i?>").val();
if($("#complain_Id_<?=$i?>").val()=='') complain_Id="";
var dataString = 'complain_Id='+ complain_Id;
$.ajax({
type: "POST",
url: "getresult.php",
data: dataString,
success: function(msg){
$('#count_display').html(msg);
}
}); //END $.ajax
});
<?php
}
?>
});
</script>
<html>
<body>
<?php
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
$button=1;
//while($row=mysql_fetch_array($result))
for($i=1;$i<11;$i++)
{
/* $date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];*/
?>
<tr>
<td style="color: #000000" ><?php echo $i;?></td>
<td style="color: #000000" id="comid"><?php echo $i; ?>
<input type="hidden" name="complain_Id_<?=$i?>" id="complain_Id_<?=$i?>" value="<?=$i?>"/> </td>
<td style="color: #000000"><?php echo $i+2;?></td>
<td style="color: #000000"><?php echo $i+3;?></td>
<td style="color: #000000"><?php echo $i+4;?></td>
<td style="color: #000000"><?php echo $i+5;?></td>
<td style="color: #000000"><?php echo $i+6;?></td>
<td id="disp" ><?php echo $i+7;?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button_<?=$i?>" id="button_<?=$i?>" />
</td>
</tr>
<?php
//$button++;
//$j=$j+1;
}
?>
</table>
</form>
<div id="count_display" >
</div>
</body>
</html>
code for display.php
<?php
$complain_Id=$_POST['complain_Id'];
echo "complain_Id=".$complain_Id;
?>
Please change code as your need. I use a hidden input field to hold complain_Id value

Sum of numbers from dynamic inner text using jquery

I would like to get the total sum of values having class addition1:::
HTML CODE is
<tr >
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Inr</td>
<td align="right" class="heading"><?php if($inr!='')echo co($inr);else echo "0.00";?> </td>
<td> </td>
<td class="heading">ROE</td>
<td class="heading" ><span class="addition1"><?php if($inr!='')echo co($inr);else echo "0.00";?> </span> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Usd</td>
<td align="right" class="heading"><?php if($usd!='')echo co($usd);else echo "0.00";?> </td>
<td> </td>
<td><input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading1" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1">
<?php if($usd!='')echo co($usd);else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Gbp</td>
<td align="right" class="heading"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($gbp!='')echo co($gbp);else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Eur</td>
<td align="right" class="heading"><?php if($eur!='')echo co($eur); else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe13" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"> <?php if($eur!='')echo co($eur); else echo "0.00";?></span>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Other</td>
<td align="right" class="heading"><?php if($other!='')echo co($other);else echo "0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<span class="addition1"><?php if($other!='')echo (co($other));else echo "0.00";?> </span>
</td>
<td> </td>
</tr>
Jquery Code is
$(document).ready(function() {
$('#tables tbody>tr>td>input.heading#roe13').change(function() {
var k = $('#roe13').val();
$('#tables tbody>tr>td.heading3').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x=Math.round(parseFloat(v*k)*100) / 100;
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe11').change(function() {
var k = $('#roe11').val();
$('#tables tbody>tr>td.heading1').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x1=Math.round(parseFloat(v*k)*100) / 100;
return x1.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe12').change(function() {
var k = $('#roe12').val();
$('#tables tbody>tr>td.heading2').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x2=Math.round(parseFloat(v*k)*100) / 100;
return x2.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr>td>input.heading#roe14').change(function() {
var k = $('#roe14').val();
$('#tables tbody>tr>td.heading4').text(function(i,v) {
v= v.replace(/,/g, ''),
asANumber = +v;
x3=Math.round(parseFloat(v*k)*100) / 100;
return x3.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
});
$('#tables tbody>tr').change(function() {
var sum = 0;
var regex = /\((\d+)\)/g;
$('span.addition1').each(function() {
matches = $(this).text().replace(/,/g, ''); alert(matches);
if( !isNaN( matches ) ){
sum += parseFloat(matches);
}
});
});
});
Class name in td can't be changed . I am trying to get the sum of values having class addition1. On running this code, 1 value is getting skipped, e.g. If I change a value say x1 then result generated due to x1 will be skipped in addition.
Please help me out.
Arrays in jquery are 0-based if you want the first value of matches use matches[0].
Don't put div's directly inside tr's. I'd recommend a span class="addition1" inside each of the td's and only round the floats you wish add.
This way you can parsefloat() first and then perform a NaN check after, stripping out all the regex stuff:
td code:
<td>..(<span class="addition1">1,230.0</span>)..</td>
jquery loop code:
$('span.addition1').each(function() {
var floatVal = parseFloat($(this).text().replace(/,/g,""));
if(!isNaN(floatVal)) {
sum += floatVal;
}
});
Use $(this).text() not .val().
$(this).val() refers to the value of the div.addition1, which does not have a value.
You are trying to nest td's inside a div which is not allowed for. If you cannot edit the TD's to give them a class you will have to use some other way of selecting them, like every eight TD or something similar.
HTML:
<tr >
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Inr</td>
<td align="right" class="heading"><?php echo $inr!=''?co($inr):"0.00";?> </td>
<td> </td>
<td class="heading">ROE</td><div class="addition1">
<td class="heading" ><?php echo $inr!=''?co($inr):"0.00";?> </td></div>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Usd</td>
<td align="right" class="heading"><?php echo $usd!=''?co($usd):"0.00";?> </td>
<td> </td>
<td><input name="roe1" id="roe11" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading1" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $usd!=''?co($usd):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Gbp</td>
<td align="right" class="heading"><?php echo $gbp!=''?co($gbp):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe12" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading2" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $gbp!=''?co($gbp):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Eur</td>
<td align="right" class="heading"><?php echo $eur!=''?co($eur):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe13" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading3" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $eur!=''?co($eur):"0.00";?>
</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td class="heading">Total Other</td>
<td align="right" class="heading"><?php echo $other!=''?co($other):"0.00";?></td>
<td> </td>
<td><input name="roe1" id="roe14" type="text" class="heading" value="1" style="width:50px" /></td>
<td class="heading4" style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-variant: small-caps; font-weight: bold;">
<?php echo $other!=''?co($other):"0.00";?>
</td>
<td> </td>
</tr>
Script:
$('table tr').change(function() {
var sum = 0;
$.each($('tr td input'), function() {
var nextCol = $(this).parent().next("td").text();
if( nextCol && ! isNaN( nextCol ) ){
sum += parseFloat(nextCol, 10);
}
});
alert(sum);
});
Just Addition:
$('table tr').change(function() {
var sum = 0;
$.each($('addition1'), function() {
var nextCol = $(this).text();
if( nextCol && ! isNaN( nextCol ) ){
sum += parseFloat(nextCol, 10);
}
});
alert(sum);
});

Issue loading content into DIV with Jquery [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I'm out of ideas and have been searching for awhile now, so hopefully someone can point me in the right direction.
I have a select box that allows a user to select a specific value. Then try to load a page using the URL/value and keep receiving a blank page.
Assuming no value is passed, it works. I've used this page in the same way quite a number of times in the past so I'm not certain whats wrong. Also, it only seems to fail if specific URL parameters are passed. I remove a substantial amount of code outside of the problem area to make it a bit easier to read.
So
$('#sheetDiv').load('loaddates.php');
will work
and
$('#sheetDiv').load('loaddates.php?project_name=' + value);
will not
Code for main page is below:
<?php
session_start();
include('db.php');
if($_POST[submit]=="Submit")
{
mysql_query("INSERT INTO tblusers SET username='".$_POST[username]."',password='".$_POST[password]."',type='".$_POST[type]."'") or print mysql_error();
}
function make_star($x)
{
$s="";
for($i=1;$i<=strlen($x);$i++)
{
$s.="*";
}
return $s;
}
?>
<head>
<script language="javascript" src="jscript/jquery.js"></script>
<script type="text/javascript" src="jscript/facefiles/jquery-1.2.2.pack.js"></script>
<script type="text/javascript" src="jscript/ddaccordion.js"></script>
<script type="text/javascript" language="javascript" src="jscript/jmenu.js"></script>
<script language="javascript" src="jscript/user.js"></script>
<script language="javascript" src="jscript/common.js"></script>
<script type="text/javascript" src="calendarDateInput.js"></script>
<script language="javascript">
function selectProject() {
$('#selectProject').show();
$('#addProject').hide();
}
function selectDate() {
$('#addProject').hide();
$('#selectDate').show();
}
function pdelete(id)
{
if(confirm('Are sure to delete the data ?')==true)
{
$.ajax({
type: "GET",
url: "ajax.php",
data: "act=delete&tbl=timesheet"+"&id="+id,
success: function(result){
$(".error").html(result);
setTimeout('window.location.reload()',2000);
}
});
}
}
checked=false;
function checkedAll (myfrm) {
var aa= document.getElementById('frm');
if (checked == false)
{
checked = true
}
else
{
checked = false
}
for (var i =0; i < aa.elements.length; i++)
{
aa.elements[i].checked = checked;
}
}
function del()
{
var flag=false;
var pass ;
for(var i=0; i<document.frm.length; i++) //check for all checkboxes
{
if( document.frm.elements[i].type=="checkbox" && document.frm.elements[i].checked==true )
{
flag=true;
}
}
if(flag == true)
{
if(confirm("Do you sure to delete this?"))
{
return true;
}else
{ return false;
}
}
if( flag==false ) // if no checkbox selected
{
alert("Please select at least one checkbox to proceed.");
return false;
}
}
function MM_openBrWindow(theURL,winName,features) {
window.open(theURL,winName,features);
return false;
}
function loadUsers(id) {
if(id !=2) {
var value = $('#selectValue').val();
alert('loadates2.php?project_name=' + value);
$('#sheetDiv').load('loaddates.php?project_name=' + value);
}
else if(id == 2) {
var value = $('#f_new_age_date').val();
$('#sheetDiv').load('loaddates.php?project_date=' + value);
}
}
function addProject() {
$('#selectProject').hide();
$('#selectDate').hide();
$('#addProject').show();
}
</script>
<style>
.selectday{
border-right:#CBCBCB 1px solid;
border-left:#CBCBCB 1px solid;
border-bottom:#CBCBCB 1px solid;
border-top:#CBCBCB 1px solid;
color:#666;
font-weight:bold;
padding-left:5px;
padding-right:5px;
}
.selectedday{
border-right:#CBCBCB 1px solid;
border-left:#CBCBCB 1px solid;
border-bottom:#CBCBCB 1px solid;
border-top:#CBCBCB 1px solid;
color:#666;
padding-left:15px;
padding-right:15px;
padding-top:7px;
}
.sday
{
color:#f69929;
font-family:Arial;
font-size:24px;
font-weight:bold;
}
</style>
<link href="css/menu.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" media="all" href="images/calendar.css" title="win2k-cold-1">
<!-- main calendar program -->
<script type="text/javascript" src="images/calendar.js"></script>
<!-- language for the calendar -->
<script type="text/javascript" src="images/calendar-en.js"></script>
<!-- the following script defines the Calendar.setup helper function, which makes
adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="images/calendar-setup.js"></script>
</head>
<div id="newContainer">
<?php if($_SESSION[usertype] == "A" || $_SESSION[usertype] == "S" ) { ?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<table width="100%" style="position:relative; left:15px;" border="0" cellspacing="0" cellpadding="0">
<?php include('header_project.php');?>
<tr>
<td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td align="center"><div id="result" align="center" style="color:#FF0000; display:block;"> </div></td>
</tr>
<tr>
<td width="15%" height="395" align="left" valign="top" colspan="2"><? include('menu.php')?></td>
<td width="100%" valign="top">
< <div id="form_news" style="width:850px; position:relative;left:52px;">
<div id="options" style="margin-left: 350px;margin-top:130px;position:absolute;z-index:2">
Add New | Select Project
</div>
<div id="addProject" style="padding-top:15px; padding: 5px; display:none; height:500px; width:950px;position:relative; top:15px;">
<table width="100%" style="position:relative; left:25px" border="0" align="left" cellpadding="0" cellspacing="0">
<tr><td colspan="8">
<form name="ff1" method="post" action="time.php">
<table width="100%" border="0" align="left" cellpadding="5" cellspacing="3">
<tr align="left">
<tr>
<td width="86" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Project</span></td>
<td width="86" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Work Code</span></td>
<td width="90" bgcolor="#e1e1e1" ><span class="text_pt space">Employee Name</span></td>
<td width="44" bgcolor="#e1e1e1" ><span class="text_pt space"> Billable Hours</span></td>
<td width="147" bgcolor="#e1e1e1" ><span class="text_pt space">Notes</span></td>
<td bgcolor="#e1e1e1" ><span class="text_pt space">Date</span></td>
<td > </td>
</tr>
<tr align="left">
<td width="132" valign="top" class="f12b"><select name="project_number" id="project_name">
<option value="">Select</option>
<?php
$aa=mysql_query("select * from projects");
while($sql=mysql_fetch_array($aa))
{
?>
<option value="<?php echo $sql['project_number']?>" ><?php echo $sql['project_name']?></option>
<?php } ?>
</select></td>
<td width="127" valign="top" class="f12b"><select name="task" id="task">
<option value="">Select</option>
<?php
$aa=mysql_query("select * from work_codes");
while($sql=mysql_fetch_array($aa))
{
?>
<option value="<?php echo $sql['work_codes']?>"><?php echo $sql['work_codes']?></option>
<?php } ?>
</select> </td>
<td width="111" valign="top" class="login_fnt"><select name="staff_name" id="staff_name">
<option value="">Select</option>
<?php
$aa=mysql_query("select * from staff_members");
while($sql_clients=mysql_fetch_array($aa))
{
?>
<option value="<?php echo $sql_clients['staff_id']?>" ><?php echo $sql_clients['staff_name']?></option>
<?php } ?>
</select></td>
<td width="47" valign="top" class="f12b"><input type="text" name="bill_hours" id="bill_hours" value="" size="5" /></td>
<td width="136" valign="top" class="f12b"><textarea name="description" id="description" cols="20" rows="1"></textarea>
<input type="hidden" name="expense_date" value="<?php echo $currdate;?>" /> </td>
<td width="185" valign="top" class="f12b">
<?php
$currdate=date('Y-m-d');
?>
<input name="new_age_date" id="f_new_age_date" onChange="document.form_news.new_rem_age_date.value=document.form_news.new_age_date.value" size="10" readonly="yes" type="text" value="<?php echo $currdate;?>">
<img src="images/img.gif" id="trigger_new_age_date" style="cursor: pointer; border: medium none;" title="Select Date">
<script type="text/javascript">
Calendar.setup({
inputField : "f_new_age_date",
ifFormat : "%Y-%m-%d",
button : "trigger_new_age_date",
singleClick : true
});
</script> </td>
<td width="41" valign="top" class="f12b"> </td>
</tr>
<tr align="left">
<td valign="top"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="login_fnt"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="f12b"> </td>
</tr>
<tr align="left">
<td valign="top"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="login_fnt"> </td>
<td valign="top" class="f12b"> </td>
<td valign="top" class="f12b"></td>
<td valign="top" class="f12b"><input type="submit" name="submit" id="submit" value="Add Time" /></td>
</tr>
</table>
</form>
</td></tr>
</table>
</div>
<div id="selectProject" style="position:relative; z-index:1; padding-top:15px; padding: 5px; display:none; height:500px; width:950px; top:125px;">
<div style="position:relative;bottom:45px">
<p style="padding:5px padding-bottom:0px;margin-left:50px; "> Select a Project:<p>
<select id ="selectValue" style="margin-left:50px;position:relative;bottom:15px;width:150px;">
<?php
$aa1 = mysql_query("select * from projects");
while(#$sql=mysql_fetch_array($aa1)) {?>
<option value="<?php echo $sql[project_name]; ?>"><?php echo $sql[project_name]; ?> </option>
<?php } ?>
</select>
<input type="button" id="selectProjectSubmit" value="Submit" onclick="loadUsers()" style="position:relative;bottom:15px;"/>
</div>
<div id="sheetDiv" style="height:500px;width:950px; border: solid 1px red; position:relative; bottom:70px;"> random </div>
</div>
</td></tr>
</table>
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
</table></td>
</tr>
<?php }?>
</div>
*****Code for loaded div below:*******
<?php
session_start();
include('db.php');
?>
<head>
<script type="text/javascript">
function updateField(id, field, project_name, date) {
if(id) {
$field = $('#'+id);
$value = $field.val();
$.ajax({
type: "GET",
url: "ajax2.php",
data: "rqt=time&idfield=" + id + "&valuefield="+$value });
}
else {
$.ajax({
type: "GET",
url: "ajax2.php",
data: "rqt=updatetime&valuefield="+ field + "&date=" + date + "&project_name=" + project_name});
}
}
function doit(id,fieldtype, newvalue) {
if(fieldtype=="staff_name" || fieldtype=="task"){
var newvalue = newvalue.options[newvalue.selectedIndex].value;
}
$.ajax({
type: "GET",
url: "ajax2.php",
data: "fieldtype=" + fieldtype + "&id=" + id + "&newvalue=" + newvalue,
});
}
</script>
</head>
<?php if($_REQUEST[project_date]){
$currDate = date('Y-m-d', strtotime($_REQUEST[project_date]));
$dayOfWeek = date('N', strtotime($_REQUEST[project_date]));
if($dayOfWeek == 7) { $dayOfWeek = 0;}
$subtractTime = "-".(string)$dayOfWeek."days";
$newdate = strtotime($subtractTime , strtotime ($currDate) ) ;
$newdate = date ( 'Y-m-d' , $newdate );
$enddate = $newdate;
}
?>
<?php
if($_SESSION[usertype] == "E") { ?>
<table width="875px" style="position:relative; left:15px;" border="0" align="left" cellpadding="0" cellspacing="0">
<td colspan="8">
<table width="100%" border="0" align="left" cellpadding="5" cellspacing="3">
<tr>
<td width="100" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Project Name</span></td>
<td width="100" bgcolor="#e1e1e1" ><span class="text_pt space">Sunday</span></td>
<td width="100" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Monday</span></td>
<td width="100" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Tuesday</span></td>
<td width="100" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Wednesday</span></td>
<td width="100" bgcolor="#e1e1e1" ><span class="text_pt space">Thursday</span></td>
<td width="100" bgcolor="#e1e1e1" ><span class="text_pt space">Friday</span></td>
<td width="100" bgcolor="#e1e1e1" ><span class="text_pt space">Saturday</span></td>
</tr>
<?php
$totalhrs=0;
$Query_dbl=mysql_query("select * from projects");
while($dbl_=mysql_fetch_array($Query_dbl))
{
$counter = 0;
?> <?php
$secondCounter = 0;
$starting = true;
while($secondCounter != 7 ) {
$newdate = $enddate;
$newdate = strtotime("".$secondCounter."day" , strtotime($newdate));
$newdate = date("Y-m-d", $newdate);
$Query_fql=mysql_query("select * from timesheet where staff_name='".$_SESSION['staff_id']."' AND project_name='".$dbl_['project_name']."'");
if($secondCounter == 0 && mysql_num_rows($Query_fql) > 0 ) {
$PN_=mysql_fetch_array($Query_fql);
?>
<tr> <td> <?php echo $PN_['project_name']; ?>
</td>
<?php $starting = false;}
$Query_sql=mysql_query("select * from timesheet where staff_name='".$_SESSION['staff_id']."' AND project_name='".$dbl_['project_name']."' AND expense_date='".$newdate."'");
$Query_xql=mysql_query("select * from timesheet where staff_name='".$_SESSION['staff_id']."' AND project_name='".$dbl_['project_name']."' AND expense_date='".$newdate."'");
$secondCounter++;
if(mysql_num_rows($Query_xql) > 0) {
$currentDate = null;
while($sql_=mysql_fetch_array($Query_sql))
{
if($currentDate != $sql_['expense_date']){
$currentDate = $sql_['expense_date'];
$cyell = mysql_query("SELECT SUM(bill_hours) AS newhours FROM timesheet WHERE expense_date='".$sql_['expense_date']."' and project_name='".$sql_['project_name']."' and staff_name='".$_SESSION['staff_id']."'");
$cardyell=mysql_fetch_assoc($cyell);
}
else {
continue;
}
?>
<td align="left">
<select style="width:100px" name="billHours" id="<?php echo $sql_['id'] ?>" onchange="updateField(this.id)">
<?php $a = 0; while($a != 15) {?>
<option value="<?php echo $a; ?>" <?php if($sql_['bill_hours'] == $a) { echo "selected"; } ?>> <?php echo $a; ?> </option>
<?php $a = $a + .5;} ?>
</select>
</td>
<?php $totalhrs += $sql_['bill_hours']; } } else{ if($starting == false) { ?> <td>
<select style="width:100px" name="billHours" id="" onchange="updateField(null, this.value, <?php echo "'".$dbl_['project_name']."'";?>, <?php echo "'".$newdate."'";?>)">
<?php $a = 0; while($a != 15) {?>
<option value="<?php echo $a; ?>" <?php if($sql_['bill_hours'] == $a) { echo "selected"; } ?>> <?php echo $a; ?> </option>
<?php $a = $a + .5;} ?>
</select>
</td> <?php } } ?>
<?php } ?> </tr> <?php }
?>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top" class="f12b"> </td>
<td colspan="2" align="right" valign="top" class="f12b"><br/><strong>Total Hours</strong></td>
<td align="center" valign="top" class="f12b">
<strong>
<?php
echo "<br/>";
echo $totalhrs;
?>
</strong></td>
<td align="left" valign="top" class="f12b"> </td>
</tr>
<tr>
<td colspan="7" align="left" valign="top"> </td>
</tr>
</table>
</td></tr>
</table>
</div>
<?php }
if($_SESSION[usertype] == "S" || $_SESSION[usertype] == "A"){ ?>
<table width="875px" style="position:relative;left:15px; bottom:0px !important" border="0" align="left" cellpadding="0" cellspacing="0">
<td colspan="8">
<table width="100%" border="0" align="left" cellpadding="5" cellspacing="3">
<tr>
<td width="20" class="login_fnt"><span class="text_pt space"> </span></td>
<td width="160" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Employee Name</span></td>
<td width="86" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Date Worked</span></td>
<td width="86" align="left" bgcolor="#e1e1e1" class="login_fnt"><span class="text_pt space">Billable Hours</span></td>
<td width="90" bgcolor="#e1e1e1" ><span class="text_pt space">Work Code</span></td>
<td width="44" bgcolor="#e1e1e1" ><span class="text_pt space">Notes</span></td>
</tr>
<?php
$Query_sql=mysql_query("select * from timesheet where project_name='".$_REQUEST['project_name']."'");
$totalhrs=0;
while($sql_=mysql_fetch_array($Query_sql))
{
?>
<tr>
<td width="20" align="left" valign="top">
<img src="redx.png" border="0" /></td>
<td width="90" align="left" valign="top" class="login_fnt"><select onchange="doit(<?php echo $sql_['id']?>, 'staff_name', this)" name="staff_name" id="staff_name">
<option value="">Select</option>
<?php
$aa=mysql_query("select * from staff_members");
while($sql_clients=mysql_fetch_array($aa))
{
?>
<option value="<?php echo $sql_clients['staff_id']?>" <?php if($sql_clients['staff_id']==$sql_['staff_name']) echo "selected";?>><?php echo $sql_clients['staff_name']?></option>
<?php } ?>
</select></td>
<td width="90" align="left" valign="top" class="login_fnt"> <input id="text" onblur="doit(<?php echo $sql_['id']?>, 'expense_date', this.value)" value="<?php echo $sql_['expense_date'];?>"/></td>
<td width="44" align="left" valign="top" class="f12b"><input type="text" onblur="doit(<?php echo $sql_['id']?>, 'bill_hours', this.value)" name="bill_hours" id="bill_hours" value="<?php echo $sql_['bill_hours']?>" size="5" />
<?php
$totalhrs=$totalhrs+$sql_['bill_hours'];
?>
</td>
<td width="86" align="left" valign="top" class="f12b"><select name="task" id="task" onchange="doit(<?php echo $sql_['id']?>, 'task', this)">
<option value="">Select</option>
<?php
$aa=mysql_query("select * from program_list");
while($sql=mysql_fetch_array($aa))
{
?>
<option value="<?php echo $sql['id']?>" <?php if($sql['id']==$sql_['task']) echo "selected";?>><?php echo $sql['sports']?></option>
<?php } ?>
</select> </td>
<td width="147" align="left" valign="top" class="f12b"><textarea name="description" onblur="doit(<?php echo $sql_['id']?>, 'description', this.value)" style="height:20px" id="description" cols="20" rows="1"><?php echo $sql_['description']?></textarea></td>
</tr><?php $i++; }
?>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"> </td>
<td align="left" valign="top" class="f12b"> </td>
<td colspan="2" align="right" valign="top" class="f12b"><br/><strong>Total Hours</strong></td>
<td align="center" valign="top" class="f12b">
<strong>
<?php
echo "<br/>";
echo $totalhrs;
?>
</strong></td>
<td align="left" valign="top" class="f12b"> </td>
</tr>
<tr>
<td colspan="7" align="left" valign="top"> </td>
</tr>
</table>
</td></tr>
</table>
<?php } ?>
You may want to use a different approach to send parameters:
$("#sheetDiv").load("loaddates.php", { "project_name": value } );
That should do the job!

Categories