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/
Related
I'm currently using Codeigniter and using Ajax to post my search result through the server and result the result and display on my responsive datatable. However the result was not added into my datatable and i even try to add it with .append but it just added below my table and the search function on datatable is not searching it and it still show "No data available in table".
Here are my View :
<div id="reporting" class="container">
<h3 class="section-title">Export Time Location Panel</h3>
<form id = "search">
<div class="form-group">
<div class="form-group">
<h5>Date/ Time</h5>
<input type="datetime-local" name="datetime" id = "datetime">
<?php echo form_error('datetime'); ?>
</div>
</div>
<button type="submit" class="btn btn-primary">Confirm</button>
</form><br/>
<table class="table table-bordered table-light" >
<thead>
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<?php include('footer.php'); ?>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
var tbl = $('.table').DataTable({
responsive: true,
"order": [[0, "desc"]]
})
$( "#search" ).submit(function(event) {
event.preventDefault();
var value = $("#datetime").val();
$.ajax({
type:'POST',
url:'<?php echo base_url(); ?>location/search_record',
data:{'datetime':value},
success:function(data){
$('.table').append(data);
}
});
});
} );
</script>
Here are my Model :
public function search_record(){ //Display Record at View Page
$this->load->model('location_model');
$this->load->library('form_validation');
echo '
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
';
}
You have to add data to table body by
success:function(data){ tbl.rows.add($(data)).draw(); }
Please check this link
https://jsfiddle.net/kuLcqwav/3/
https://datatables.net/examples/api/add_row.html
So im kinda trying to delete row from my mysql database using checkboxes. Here is my code. Would be glad if someone could write me down simple delete code. Tryed many but failed, stuck for hours with this :(
<html>
<head>
<title>Admin, User</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'title_bar.php';?>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php
if(isset($_POST['submit2']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis)){
echo "<p>Privalomi visi langai!</p>";
}
else {
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == TRUE)
{
header('location:kurtisalinti.php');
}
else {
echo "<p>Klaida!</p>";
}
}
?>
<p>Uzduoties pavadinimas:
<p><input type='text' name='pav' />
<p>Uzduotis:
<p><textarea name='uzduotis'></textarea>
<p><input type='submit' name='submit2' value='Sukurti Uzduoti' />
</form>
</p></p></p></p>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<?php
$query = mysqli_query($database,"SELECT uzid,pav,uzduotis FROM uzduotys");
$count=mysqli_num_rows($query);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Pavadinimas</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aprasymas</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($query)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $row['uzid']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzid']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['pav']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzduotis']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Istrinti Uzduotis"></td>
</tr>
<?php
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Welcome to StackOverflow! Generally as a rule of thumb asking to write you some code doesn't get you very far, however I know that some people learn better from seeing it implemented and being able to modify off of that.
There is a number of ways you can do this. Using something like jquery and ajax you can post your requests without having to reload the page. Keep in mind what I have below may not fully work for you since taking the time to do this much already without a database or connection should give you an idea of what you're looking to do. Good luck!
CAUTION: PSUEDO CODE (This may not fully work and is not intended for production) The idea is to show you an approach to achieving what you are looking for.
<?php
include('connect.php');
include('functions.php');
include('title_bar.php');
if(isset($_POST['submit-uzduotis']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis))
{
$result = "<span>Privalomi visi langai!</span>";
}
else
{
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == true)
{
header('location:kurtisalinti.php');
}
else
{
$result = "<span>Įvyko klaida!</span>";
}
}
if(isset($_POST['remove']))
{
$id = mysql_real_escape_string($_POST['remove']);
mysqli_query($database, "DELETE FROM uzduotys WHERE uzid = $id");
}
function showTableData()
{
$query = mysqli_query($database, "SELECT uzid, pav, uzduotis FROM uzduotys");
$count = mysqli_num_rows($query);
while($row = mysqli_fetch_array($query))
{
echo '<tr id="'. $row['uzid'] .'">
<td>
<input type="checkbox" name="checkbox[]" value="'. $row['uzid'] .'">
</td>
<td>'. $row['uzid'] .'</td>
<td>'. $row['pav'] .'</td>
<td>'. $row['uzduotis'] .'</td>
<td>
<button id="remove-single" data-id="'. $row['uzid'] .'">REMOVE</button>
</td>
</tr>';
}
}
?>
<html>
<head>
<title>Admin, User</title>
<style>
.uzduotis-table {
background-color: #ccc;
border-collapse: collapse;
}
.uzduotis-table thead > td {
background-color: #333;
font-weight: bold;
}
.uzduotis-table td {
padding: 3px;
text-align: center;
background-color: #fff;
}
label {
display:block;
position:relative;
font-weight: bold;
}
</style>
</head>
<body>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php echo $result; ?>
<div>
<label>Uzduoties pavadinimas:</label>
<input type='text' name='pav' />
</div>
<div>
<label>Uzduoties:</label>
<textarea name='uzduotis'></textarea>
</div>
<div>
<input type='submit' name='submit-uzduoties' value='Sukurti Uzduoti' />
</div>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<table class="uzduotis-table">
<thead>
<tr>
<td>#</td>
<td>Id</td>
<td>Pavadinimas</td>
<td>Aprasymas</td>
</tr>
</thead>
<tbody>
<?php showTableData(); ?>
<tr>
<td colspan="5">
<button id="remove-selected" data-id="'. $row['uzid'] .'">REMOVE SELECTED</button>
</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
// Remove Single (Button)
$('body').on('click', '#remove-single', function() {
remove($(this).data('id'));
});
// Remove All Checked
$('body').on('click', '#remove-selected', function() {
$('.uzduotis-table tr').filter(':has(:checkbox:checked)').each(function() {
remove(this.id);
});
});
function remove(id)
{
console.log("Remove: " + id);
alert('Removing: ' + id);
$.ajax({
type: "POST",
url: '<?php echo $url; ?>',
data: { remove: id },
success: function (data) {
$('#' + id).remove();
}
});
}
})
</script>
</body>
</html>
I cleaned up a bit of the html and styles, just made it easier for me to read. Also I would recommend looking into a library such as PDO to handle your database queries as there currently isn't much in place to protect or safe guard against sql injection.
I want to store a session variable and echo it. I don't know how to do this.
At the moment I have the following code:
<script>
function changecolor(obj)
{
obj.style.backgroundColor="yellow";
}
</script>
<table id="table">
<tr>
<td id="glow1" bgcolor="green" onclick="changecolor(this)" >8-9 /td><br>
<td id="glow2" bgcolor="green" onclick="changecolor(this)" >9-10 /td><br>
<td id="glow3" bgcolor="green" onclick="changecolor(this)" >10-11 /td><br>
</tr>
</table>
<form action="sample.php" method="post">
<input type="submit" name="submit" value="confirm">
</form>
JS :
function changeColor(color) {
$.ajax({
type: "POST",
data: {
'color': color
},
url: '/url/to/script.php',
cache: false,
success: function(data){
$('#table td').css('background-color',data);
}
});
}
index.php :
<?php
session_start();
if (isset($_SESSION['color'])) {
$color = $_SESSION['color'];
}else{
$color = '#FFFFFF';
}
?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<table id="table" border="1">
<tr>
<td onclick="changeColor('#FF0000');" bgcolor="<?php echo $color;?>">Turn red</td>
</tr>
<tr>
<td onclick="changeColor('#00FF00');" bgcolor="<?php echo $color;?>">Turn green</td>
</tr>
<tr>
<td onclick="changeColor('#0000FF');" bgcolor="<?php echo $color;?>">Turn blue</td>
</tr>
</table>
</body>
</html>
script.php
<?php
session_start();
$_SESSION['color'] = $_POST['color'];
echo $_POST['color'];
?>
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!
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";
?>