change local URL based on dopdown list - javascript

I want to change the local URL (on/of the same page) from
example.php
to
example.php?month=year-month
I have following script:
<script type=\"text/javascript\">
function select() {
var url = window.location.href;
var year = document.getElementById('myyear').value;
var month = document.getElementById('mymonth').value;
document.my_months.action = url + '?month=' + year + '-' + month;
}
</script>
And follwing form:
echo "<form id =\"my_months\" name= \"my_months\" method=\"post\" onsubmit=\"return select();\">
<select name = \"myyear\" id = \"myyear\">";
foreach (range(2012, date('Y')) as $years) {
if ($years == date('Y')) {
echo "<option value= \"".$years."\" selected= \"".$years."\">".$years."</option>";
} else {
echo "<option value= \"".$years."\">".$years."</option>";
}
}
echo "</select>
<select name = \"mymonth\"> id = \"mymonth\"";
foreach ($myMonths as $id => $months) {
if ($months == date('F')) {
echo "<option value= \"".$id."\" selected= \"".$id."\">".$months."</option>";
} else {
echo "<option value= \"".$id."\">".$months."</option>";
}
}
echo "</select>
<input type=\"submit\" id=\"Submit_m\" name=\"Submit_m\" value=\"Ok\">
</form>";
But it doesn't work. The page will be reload without modifying the URL!
What I'm doing wrong here?
Here is the code:
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" dir=\"ltr\">
<head>
<title>title</title>
<meta name=\"description\" content=\"\" />
<meta name=\"robots\" content=\"index,follow\" />
<meta name=\"keywords\" content=\"\" />
<!--<meta http-equiv=\"refresh\" content=\"5\">-->
<script type=\"text/javascript\" language=\"javascript\" src=\"../js/jquery-1.9.1.js\"></script>
<script type=\"text/javascript\" language=\"javascript\" src=\"../js/modules/exporting.js\"></script>
<script type=\"text/javascript\">
function select() {
var url = window.location.href;
var year = document.getElementById('myyear').value;
var month = document.getElementById('mymonth').value;
document.my_months.action = url + '?month=' + year + '-' + month;
}
</script>
<script type=\"text/javascript\">
$(document).ready(
function () {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
zoomType: 'xy'
},
...
});
}
)
</script>
</head>
<body>";
//here some data and arrays
echo "<form id =\"my_months\" name= \"my_months\" method=\"post\" onsubmit=\"return select();\">
<select name = \"myyear\" id = \"myyear\">";
foreach (range(2012, date('Y')) as $years) {
if ($years == date('Y')) {
echo "<option value= \"".$years."\" selected= \"".$years."\">".$years."</option>";
} else {
echo "<option value= \"".$years."\">".$years."</option>";
}
}
echo "</select>
<select name = \"mymonth\"> id = \"mymonth\"";
foreach ($myMonths as $id => $months) {
if ($months == date('F')) {
echo "<option value= \"".$id."\" selected= \"".$id."\">".$months."</option>";
} else {
echo "<option value= \"".$id."\">".$months."</option>";
}
}
echo "</select>
<input type=\"submit\" id=\"Submit_m\" name=\"Submit_m\" value=\"Ok\">
</form>
<p><div id=\"container\" style=\"min-width: 200px; height: 400px; margin: 0 auto\"></div></p></body></html>";

<script type=\"text/javascript\">
function select() {
var url = window.location.href;
var year = document.getElementById('myyear').value;
var month = document.getElementById('mymonth').value;
url += '?month=' + year + '-' + month;
// set the url in your location bar
history.pushState({date:"true"}, "", url);
}
</script>

all suggested tries were not successfull. However I've changed the method of the form from post to get and the url changed to
example.php?myyear=myyear_value&mymonth=mymonth_value&Submit_m=OK
whwn submiting the button named Submit_m
With these variables I'm now abel to the get the values with $_GET['myyear'] and $_GET['mymonth']
Now I get the behavior expected

Related

how to append data using ajax posts and datatables are not working?

Hello there am trying to get the data from database using ajax posts but i didn't get any data properly. first column data is splinting in another columns(Member names are coming in image field and info field). Image also shared please check that. And also datatables are not working while fetching the data using Ajax. Help me out from this problem...
Thanks & Regards
<body>
<label>Party</label>
<select id='partydropdown' name='partydropdown' onchange="partyFunction();">
<option>--select a party--</option>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
?>
<option value="<?php echo $row["Id"];?>">
<?php echo $row["PartyName"];?>
</option>
<?php }}?>
</select>
<div id="showhide"></div>
</body>
<script type="text/javascript">
function partyFunction(){
debugger;
$("#showhide").empty();
$("#showhide").html('');
$("#showhide").append("<table class='table table-bordered text-center table-responsive' border='1px' id='example'>"+
"<tr>"+
"<th>PartyMemberName</th>"+
"<th>Image</th>"+
"<th>Info</th>"+
"</tr>"+
"<tbody id='partyBody'>"+
"</tbody>"+
"</table>"
);
$postdata = {};
$postdata["Id"]=$("#partydropdown").val();
console.log($("#partydropdown").val());
$.post('test_data.php',$postdata,function (data) {
debugger;
console.log(data);
console.log(data["data"][0].candiateName);
$("#partyBody").empty();
$("#partyBody").html('');
console.log(data["data"]);
console.log(data["data"].length);
for(var i=0; i<data["data"].length; i++){
if(data["data"][i].candiateName != null){
$("#partyBody").append("<tr>"+
"<td id='resdata"+i+"'></td>"+
"<td id='resdata1"+i+"' ></td>"+
"<td id='resdata2"+i+"'></td>"+
"</tr>");
$("#resdata"+i).text(data["data"][i].candiateName);
$("#resdata1"+i).append("<img id='photo"+i+"'>");
$("#resdata2"+i).text(data["data"][i].Background);
$("#photo"+i).attr('src', 'http://aptsvotes.com/wp-content/themes/apts2019/img'+data["data"][i].Photo );
}
}
});
};
</script>
here is the test_data.php code
<?php
include_once "conn.php";
include_once "voterdbclass.php";
session_start();
$tbl_name2="Parties";
$dbObj = new Database1();
$values1 = array("all");
$querys = "SELECT c1.CandidateName,c1.Photo,c1.Background ,c1.Type FROM aptsv1_votes.Parties p1 LEFT JOIN aptsv1_votes.Candidates c1 ON c1.CurrentPartyId = p1.Id where p1.Id ='" . $_POST['Id'] . "' limit 21";
$res = $dbObj->SelectRecord($tbl_name2,$values1,"","$querys");
$data=array();
$i=0;
while ($rs = $res->fetch_array(MYSQLI_ASSOC)) {
$data[$i]['candiateName']=$rs['CandidateName'];
$data[$i]['Photo']=$rs['Photo'];
$data[$i]['Background']=$rs['Background'];
$i++;
}
$json_array= array(
"data" =>$data
);
echo json_encode($json_array);
?>
for(var i=0; i<data["data"].length; i++){
if(data["data"][i].candiateName != null){
var imge = data["data"][i].Photo;
var name = data["data"][i].candiateName;
var bg = data["data"][i].Background;
$("#partyBody").append("<tr>"+
"<td id='resdata" + i + "'>" + name+"</td>"+
"<td id='resdata1" + i + "' ><img id= 'photo" + i + "' src='http://aptsvotes.com/wp-content/themes/apts2019/img'" + imge+"></td>"+
"<td id='resdata2" + i + "'>" + bg+"</td>"+
"</tr>");
}
}
You have to parse JSON data into the first script. While ajax result you posting with json_encode, I found missing
var data = $.parseJSON(data);
console.log(data["data"].length);
into code
$.post('test_data.php',$postdata,function (data) {
// debugger;
console.log(data);
var data = $.parseJSON(data); // Add this line in your code and verify
console.log(data["data"].length);
Thank you!

How to apply table classes to AJAX response table

I have a table to show data from the AJAX request made. Although the data is displaying for all the three radio choices made, my prob here is that as I have classes applied on the table that holds good for pagination purposes, the data displaying does not follow the classes applied on the table i.e. I have pagination that shows 10 records each time and then next page shows next 10 records. I am posting my code here and wish to have some insight or help over this.
<?php include 'blocks/headerInc.php' ; ?>
<?php require_once "phpmailer/class.phpmailer.php";?>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<?php
ob_start();
$errmsg = "" ;
$module_id = '';
$query = '';
$date_from = '';
$date_to = '';
$status ='';
$check ='';
$disabled='';
$row='';
$sqlQuery = "SELECT * FROM tbl_user WHERE type = 3 AND status = 0 AND registration_type = 0";
?>
<div class="container pagecontainer">
<!-- Static navbar -->
<div class="row row-offcanvas row-offcanvas-right">
<!--/.col-xs-12.col-sm-9-->
<div class="col-sm-3 col-md-3 sidebar" id="sidebar">
<div id="left_panel" class="clearfix left">
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Candidate Approval</div>
<div class="panel-body">
<div class="column col-sm-offset-0">
<form id="selection" method="GET" >
<input type='radio' name='users' value='unapproved' checked /> Unapproved Candidates
<input type='radio' name='users' value='approved' /> Approved Candidates
<input type='radio' id='show' name='users' value='all' /> All Candidates
<table id="example" class="table table-striped table-hover table-bordered dataTableReport dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>S.No.</th>
<th>Email ID</th>
<th> Reference ID</th>
<th>Name</th>
<th>Mobile No.</th>
<th>Registration Date</th>
<th>Check for Approval
<input type="checkbox" id="select_all" name="all_check[]" <?php echo $disabled ;?> class="checkbox" value= "<?php //echo $row['id']; ?>"> </th>
</tr>
</thead>
<tbody id=datashow>
</tbody>
</table>
<input type="submit" name ="all_send" value="Approve" style="display: none; float: right;" id="one" class="btn btn-success">
</form>
</div>
</div>
</div>
<!--/row-->
</div>
<!--/.sidebar-offcanvas-->
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$('#selection').change
(
function()
{
var selected_value = $("input[name='users']:checked").val();
$.ajax
(
{
url: "approval_ajax.php",
type: "POST",
cache: false,
data: { selected_value : selected_value },
success: function(response)
{
console.log(response);
var len = response.length;
$("#datashow").empty();
for(var i=0; i<len; i++){
var id = response[i].id;
var email = response[i].email;
var employee_id = response[i].employee_id;
var first_name = response[i].first_name;
var middle_name = response[i].middle_name;
var last_name = response[i].last_name;
var mobile = response[i].mobile;
var created_on = response[i].created_on;
var disabled = response[i].disabled;
var users = response[i].users;
var tr_str =
"<tr>" +
"<td>" + (i+1) + "</td>" +
"<td>" + email + "</td>" +
"<td>" + employee_id + "</td>" +
"<td>" + first_name + " " + middle_name + " " + last_name + "</td>" +
"<td>" + mobile + "</td>" +
"<td>" + created_on + "</td>" +
"<td><input type='checkbox' name='check[]'" + disabled + "value= '" + id + "' class='checkbox' id='select_all' ></td>" +
"<input type='hidden' value='" + id + "' name='user_id' id='user_id' >" +
"</tr>" ;
$("#datashow").append(tr_str);
}
}
}
);
}
);
</script>
<script>
$(function() {
$('input[name="check[]"]').click(function() {
var checkedChbx = $('[type=checkbox]:checked');
if (checkedChbx.length > 0) {
$('#one').show();
} else {
$('#one').hide();
}
});
});
$(document).ready(function() {
var $submit = $("#one");
$submit.hide();
var $cbs = $('input[name="all_check[]"]').click(function() {
$('input[name="check[]"]').prop('checked',$(this).is(":checked"));
$submit.toggle($(this).is(":checked")); //use this to get the current clicked element
});
});
</script>
<script type="text/javascript">
var select_all = document.getElementById("select_all"); //select all checkbox
var checkboxes = document.getElementsByClassName("checkbox"); //checkbox items
//select all checkboxes
select_all.addEventListener("change", function(e){
for (i = 0; i < checkboxes.length; i++) {
checkboxes[i].checked = select_all.checked;
}
});
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].addEventListener('change', function(e){ //".checkbox" change
//uncheck "select all", if one of the listed checkbox item is unchecked
if(this.checked == false){
select_all.checked = false;
}
//check "select all" if all checkbox items are checked
if(document.querySelectorAll('.checkbox:checked').length == checkboxes.length){
select_all.checked = true;
}
});
}
</script>
<script>
// set users via PHP
var users = "<?php if (isset($_POST['users'])) echo $_POST['users']; ?>";
// update the HTML without interfering with other scripts
(function(users){
// check if PH
if (users.length) {
// update the radio option...
var inputTag = document.querySelector('input[value="'+users+'"]');
if (inputTag)
inputTag.checked = true;
// if users is "all"
// hide the last TD of every column
if (users == "all") {
var lastTh = document.querySelector('tr th:last-child');
lastTh.style.display = "none";
var allLastTds = document.querySelectorAll('td:last-child');
for (var i = 0; i< allLastTds.length; i++) {
allLastTds[i].style.display="none";
}
}
if (users == "approved") {
thInputTag = document.getElementById("select_all");
thInputTag.setAttribute("disabled", true);
}
var form = document.querySelector("form");
var inputName = document.querySelectorAll('input[name="users"]');
for (var j=0; j<inputName.length; j++)
inputName[j].onclick=function(){
form.submit();
};
}
})(users);
</script>
<?php include 'blocks/footerInc.php'; ?>
approval_ajax.php:
<?php
session_start();
require("../includes/config.php");
require("../classes/Database.class.php");
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$return_arr = array();
$status='';
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$value = filter_input(INPUT_POST, "selected_value");
if (isset($value))
{
$users = $value;
}
else
{
$users='';
}
switch ($users)
{
case "all":
$sqlQuery = "SELECT * FROM tbl_user WHERE type =3";
break;
case "approved":
$sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =1";
break;
}
$sq = $db->query($sqlQuery);
if ($db->affected_rows > 0)
{
while ($row = mysql_fetch_array($sq))
{
$disabled = '';
if ($status == '1')
{
$disabled = "disabled = 'disabled' checked='checked' ";
}
$id = $row['id'];
$email = $row['email'];
$employee_id = $row['employee_id'];
$first_name = $row['first_name'];
$middle_name = $row['middle_name'];
$last_name = $row['last_name'];
$mobile = $row['mobile'];
$created_on1 = $row['created_on'];
$created_on = date("d-m-Y", strtotime($created_on1));
$return_arr[] = array("id" => $id,
"email" => $email,
"employee_id" => $employee_id,
"first_name" => $first_name,
"middle_name" => $middle_name,
"last_name" => $last_name,
"mobile" => $mobile,
"created_on" => $created_on
"disabled" => $disabled
);
}
}
header('Content-Type: application/json', true, 200);
echo json_encode($return_arr);
}
Well i think that id should be in quotation but in your code <tbody id=datashow> doesn't having any quotation may be you can change it like below
<tbody id="datashow">

HTML textarea show br

i have a textarea in HTML. In the textarea the blank line is is looks br.
I try to have the value of the some text. And posting with get. After i received with php. And i changed the value of the some text to variabled i get with get.
Like this :
a<br />b c
Code (post with javascript):
<script type="text/javascript">
function nl2br (str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
function menusec(secilen){
var deger = secilen.options[secilen.selectedIndex].value;
var urunadi = document.getElementById("okulueua").value;
var urunfiyati = document.getElementById("okulueuf").value;
var kargofiyati = document.getElementById("okuluekf").value;
var aciklama = nl2br(document.getElementById("okulueat").value);
alert(aciklama);
window.location.href = "okulue.php?menu=" + deger + "&urunadi=" + urunadi + "&urunfiyati=" + urunfiyati + "&kargofiyati=" + kargofiyati + "&aciklama=" + aciklama;
}
</script>
Code (get with php) :
<?php
if (isset($_GET['menu'])) {
$secilendeger = filter_input(INPUT_GET, "menu");
$urunadiget = filter_input(INPUT_GET, "urunadi");
$urunfiyatiget = filter_input(INPUT_GET, "urunfiyati");
$kargofiyatiget = filter_input(INPUT_GET, "kargofiyati");
$aciklamaget = filter_input(INPUT_GET, "aciklama");
echo($aciklamaget);
?>
<script type="text/javascript">
function br2nl($content){
$content = str_ireplace("<br /> ", "\n", $content);
return $content;
}
function br2nl1($input){
return preg_replace('/<br(\s+)?\/?>/i', "\n", $input);
}
document.getElementById("menusecme1").style.width = "315px";
document.getElementById("okulueua").value = "<?php echo($urunadiget); ?>";
document.getElementById("okulueuf").value = "<?php echo($urunfiyatiget); ?>";
document.getElementById("okuluekf").value = "<?php echo($kargofiyatiget); ?>";
document.getElementById("okulueat").value = "<?php echo($aciklamaget); ?>";
$('select[name^="ms1"] option[value="<?php echo($secilendeger); ?>"]').attr("selected","selected");
</script>
Code (HTML) :
<input type="text" class="okulueuat" name="okulueua" id="okulueua">
<input type="text" class="okulueua2t" name="okulueua2" value="1000" readonly="yes">
<input type="text" class="okulueuft" name="okulueuf" id="okulueuf">
<input type="text" class="okuluekft" name="okuluekf" value="5" id="okuluekf">
<input type="submit" class="tamamb2" value="Tamam" name="submit">
<input type="button" class="iptalb2" value="İptal" onclick="location='okulul.php'">
<input type="file" name="okuluef[]" class="resimeklec" multiple="multiple">
<textarea id="okulueat" name="okuluea"></textarea>
How can i solve this problem?
I need your help.
Note : I don't have a good English. Pardon me. I hope you understand.
Try this:
<textarea>a
b c</textarea>

When the timer count down to zero the form is not getting submitted

I am using a form with countdown timer. When the timer becomes zero the form should automatically submitted. But the submission is not successfully done. When the timer comes to '0' it just stops. I am giving my code here.
Please find the mistake I have done.
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input[type='checkbox']").change(function() {
if ($(this).is(":checked"))
{
$(this).closest("thead").addClass("redBackground");
}
else
{
$(this).closest('thead').removeClass("redBackground");
}
});
});
</script>
<script language="javascript">
function over() {
document.getElementById("submit").disabled = true;
}
function time() {
var minute = Math.floor(timeleft / 60);
var seconds = timeleft % 60;
if (timeleft <= 0)
{
clearTimeout(timer);
document.getElementById("submit").submit();
}
else
{
if (minute < 10)
{
minute = "0" + minute;
}
if(seconds < 10)
{
seconds = "0" + seconds;
}
document.getElementById("timer").innerHTML = minute + ":" + seconds;
}
timeleft--;
var timer = setTimeout(function(){time()}, 1000);
}
</script>
<style>
</head>
<body onload="time()">
<script>
var timeleft = 2 * 60;
</script>
<?php
include('connect.php');
session_start();
$sql = "select * from test";
$query = mysql_query($sql);
$i = 0;
echo "<div id='timer'></div>";
echo"<form method='post' action='test2.php' name='exam' id='exam'>";
while($row = mysql_fetch_array($query))
{
echo "<center><table border='0'>";
echo "<thead>";
$i++;
echo "<td colspan='4'>";
echo "<input type='checkbox' id='$i' name='$i'>";
echo $i . ".";
echo "&nbsp";
echo $row['question'];
echo "</td>";
echo "</thead>";
echo "<tr>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='A'>";
echo "(A)&nbsp&nbsp";
echo $row['opt1'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='B'>";
echo "(B)&nbsp&nbsp";
echo $row['opt2'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='C'>";
echo "(C)&nbsp&nbsp";
echo $row['opt3'];
echo "</td>";
echo "<td class='ans'>";
echo "<input type='radio' name='ans$i' value='D'>";
echo "(D)&nbsp&nbsp";
echo $row['opt4'];
echo "</td>";
echo "</tr>";
echo "</table></center>";
echo "<br>";
}
echo "<center><input type='submit' name='submit' value='submit' id='submit' onclick='over();'></center>";
echo "</form>";
$_SESSION["qs"] = $i;
?>
</body>
</html>
Use the submit() method of the <form> instead of trying to call it on the submit button.
// 'exam' is the ID of your form
document.getElementById('exam').submit();
The following should work. The problem seems that you gave your submit button an id of submit which will override the submit() method of the form. So I renamed the button to submitButton and it works.
var timer,
timeleft = 5; // 5 seconds
function time()
{
var minute = Math.floor(timeleft / 60);
var seconds = timeleft % 60;
if (timeleft >= 0)
{
if (minute < 10)
{
minute = "0" + minute;
}
if (seconds < 10)
{
seconds = "0" + seconds;
}
document.getElementById("timer").innerHTML = minute + ":" + seconds;
}
if (timeleft <= 0)
{
clearTimeout(timer);
document.getElementById("exam").submit();
return;
}
timeleft--;
timer = setTimeout(time, 1000);
}
time();
<form id="exam" action="http://www.google.com/search" type="get">
<input type="text" name="q" value="Test">
<input type="submit" value="Submit" id="submitButton">
</form>
<div id="timer"></div>
Try below code:
document.getElementById('submit').click();
document.getElementById('submit').trigger('click');
Wrote a sample code for showing a decremented countdown timer on each second. At the end when the timer will come to "0" it's calling a function sendFormDataToServer() which can be used to do rest of calculation.
Check once. Maybe it'll solve your problem.
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var countdown_limit = 5;
// print the countdown message
function showCountDownMsg(countdown_limit){
$('#countdown').html(countdown_limit+' Sec Left');
}
showCountDownMsg(countdown_limit);
// Refresh countdown timer in every 1sec(1000ms)
var refreshInterval =setInterval(function(){ refreshCountDown(); }, 1000);
// function for refresh countdown timer
function refreshCountDown(){
console.log('all is well');
countdown_limit--;
showCountDownMsg(countdown_limit);
if(countdown_limit === 0){
console.log("Countdown stopped");
clearInterval(refreshInterval);
// Call function to send form data to server
sendFormDataToServer();
}
}
function sendFormDataToServer(){
console.log('EXtracting form data & Sending those to server ');
}
});
</script>
</head>
<body>
<div id='countdown'></div>
</body>
</html>

How to get $_POST working with my editable jquery table?

I have this editable html table that I've got working, so you can click the cells and edit the text, however I can't get it to post the values as well.
I know there's a problem with the 5 lines of code under the comment on script.js
test.php
<h2><u>Edit</u></h2>
<form action="ajax/name.php" name="edit_template_form" id="edit_template_form" method="post">
<?php print "<table border=\"1\" class=\"editableTable\">
<tr>
<th>Template Name</th>
<th>Template Description</th>
</tr>";
foreach($res as $row){
$temp_description = $row['template_description'];
echo "<tr>";
echo "<td id=\"edit_name\" name=\"edit_name\">". $row['template_name']. "</td>";
echo "<td id=\"edit_template\" name=\"edit_template\">". nl2br($temp_description). "</td>";
echo "<tr/>";
}
print "</table>"; ?>
</form>
<div id="template_edit"></div>
name.php
if (isset($_POST['edit_template'])) {
$template_edit = $db->escape($_POST['edit_template']);
$user = $db->escape($user);
$db->update('templates', array('template_description' => $template_edit), 'AND userID="'.$user.'"');
echo $_POST['edit_template'];
}
if (isset($_POST['edit_name'])) {
$template_name = $db->escape($_POST['edit_name']);
$user = $db->escape($user);
$db->update('templates', array('template_name' => $template_name), 'AND userID="'.$user.'"');
echo $_POST['edit_name'];
}
script.js
$(function () {
$("td").dblclick(function () {
var OriginalContent = $(this).text();
$(this).addClass("cellEditing");
$(this).html("<input type='text' value='" + OriginalContent + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
//POST values
var edit_template = $('#edit_template').val();
var edit_name = $('#edit_name').val();
$.post('ajax/name.php', {edit_name: edit_name, edit_template: edit_template}, function(data) {
$('div#template_edit').text(data);
});
var newContent = $(this).val();
$(this).parent().text(newContent);
$(this).parent().removeClass("cellEditing");
}
});
$(this).children().first().blur(function(){
$(this).parent().text(OriginalContent);
$(this).parent().removeClass("cellEditing");
});
});
});

Categories