last modified date after edit function - javascript

I want to display a "Last modified time" in my javascript table. I have searched a lot on date time but I can only find the last modified time on the document. I have some variables in my table (see below question). What i want to do is display the date after i was modified that variable. Can anyone help me ? :)
The table what im using with javascript.
`
if(response.length > 0)
{
for (var count = 0;count < response.length; count++)
{
html += '<tr>';
html += '<td>' +response[count].id+'</td>';
html += '<td>€'+response[count].inkoopprijs+'</td>';
html += '<td>€'+response[count].verkoopprijs+'</td>';
html += '<td>' +response[count].producten+'</td>';
html += '<td>' +response[count].create_date+'</td>';
html += '<td>' +response[count].last_modified+'</td>';
html += '<td><a href="../prijswijzigen.php?edit='+response[count].id+'" class="edit_btn">Edit</td>';
html += '<td><a onclick="return confirm()" href="crud.php?del='+response[count].id+'" class="del_btn">Delete</td>';
html += '</tr>';
serial_no++;
}
}
`
html += '<td>' +response[count].last_modified+'</td>';
That line is for my variable last modified that is the same as my create_date variable.
The DOM lastModified property in HTML. That displayed the time of the last time i modified the file.

new Date().toLocaleDateString()
is that what you need?

Related

How to generate a mark sheet with names from an array and display with textbox beside?

I am trying to create a mark sheet for a project am currently working on where i have an array of names such as
var names = ["n1","n2","n3","n4","n5","n6","n7","n8"];
and i want to display the names in a table column and generate an amount of text boxes which is defined in a loop but so far i am having trouble to display the text boxes side by side of the names.
html+= "<table>";
html+= "<table style='border:1px solid black;'><tr><th>Student Name</th><th>ICA's</th>";
for(var i = 0; i<=names.length;i++)//retrieve names from the array
{
for(var j=1;j<=2;j++)//amount of textboxes need to be created
{
html+= ("<tr><td id='tableTD'>"+names[i]+"</td><td>"+txtBox+"</td></tr></table>");
}
}
display.innerHTML = html;
}
the result from this segment of codes is that i get a duplicate of the names with textbox beside them but not all in 1row for example "n1: textbox1, textbox2"
i have to display all that in a tables and i am limited to only html and javascript no jquery of server side language.
I cant seem to understand where the problem come from..
Is this more like what you're trying to do?
html = "<table>";
html+= "<tr><th>Student Name</th><th>ICA-1/th><th>ICA-2</th><th>Total</th></tr>";
for(var i = 0; i<=names.length;i++)//retrieve names from the array
{
html += "<tr id='row" + i +"'><td>"+names[i]+"</td>";
for(var j=1;j<=2;j++)//amount of textboxes need to be created
{
html+= "<td>"+txtBox+"</td>";
}
html += "<td id='total" + i "'> </td></tr>";
}
html += "</table>";
display.innerHTML = html;
additional code based on further questions below: (additional edits above and below to add totals to each row)
for (let row=0; row<names.length; row++)
{
let txtValue=document.querySelectorAll("#row" + row + " .stdMrk");
if(txtValue.length>0)
{
let rowTotal = 0;
for(var i = 0;i<=y;i++)
{
rowTotal += parseInt(txtValue[i].value);
}
//alert(rowTotal);
document.querySelector("#total" + row).innerHTML = rowTotal;
}
}
This outer loop gets the inputs for each row, then uses your loop to add them.
#Noah B
The below codes is the ans i got from you to display the tables which ive modified it abit to acomodate my requirements.
for(var i = 0; i<names.length;i++)//retrieve names from the array
{
html += "<tr id='row" + i +"'><td style='border:1px solid black;'>"+names[i]+"</td>";
for(var j=1;j<=2;j++)//amount of textboxes need to be created
{
html+= "<td style='border:1px solid black;'><input type='text' class='stdMrk' placeholder='0' value='0' /></td>";
}
for(var k=1;k<=1;k++)//display project or final exams txt box
{
html+= "<td style='border:1px solid black;'><input type='text' class='stdMrk' placeholder='0' value='0' /></td>";
}
html += "</tr>";
}
But my other issue is that now i need to retrieve the value of each rows and from what you can see,ive added an additional for loop to display another set of textboxes which has the same class name as the previous one.
For example n1 will have 3int value entered from the keyboard and i have to compute that 3value and return it. It must be a loop which get repeated for each names.
This is the codes i've written to retrieve the value but it display all the value 1by 1 without any means to know from which rows this belong to..
var txtValue = document.getElementsByClassName("stdMrk");
if(txtValue.length>0)
{
for(var i = 0;i<=y;i++)
{
x += parseInt(txtValue[i].value);
}
alert(x);
}//edit ive manage to create this but still need to iterate through all the names...
Thanks in advance..

Print every record of loop in a separate page in ajax success

How to print every record of loop in a separate page, While getting data through ajax and PHP in array. i.e
I want row1 data in every page, And row2 data every record in a separate page.
Trying the following script, not giving the desired result.
var response = {
row1: [{group: 'Group A'}],
row2: [
{team: 'Team A', player: 'Jema', result: 43},
{team: 'Team B', player: 'Deno', result: 34},
{team: 'Team B', player: 'Niob', result: 56},
{team: 'Team B', player: 'Skion', result: 49},
],
};
$("#group").html(response.row1.group);
var cats = {};
response.row2.forEach(function(element) {
cats[element.team] = cats[element.team] || [];
cats[element.team].push(element);
});
Object.keys(cats).forEach(function(team) {
let html = '';
html = '<tr>';
html += '<td>' + team + '</td>';
html += '</tr>';
$('table').append(html);
// Loop through the results for this category
cats[team].forEach(function(element) {
var names = element.player;
var result = element.result;
html = '<tr>';
html += '<td>' + names + '</td>';
html += '<td><input type="text" value="' + result + '"></td>';
html += '</tr>';
$('table').append(html);
});
// Append the textarea at the end of the results
html = '<tr>';
html += '<td><textarea placeholder="textarea..."></textarea></td>';
html += '</tr>';
$('table').append(html);
});
var PrintThis = document.getElementById('print');
var PrintStyle = '<style type="text/css">' +
'#media print{' +
'.Break { page-break-after: always }' +
'}' +
'</style>';
PrintStyle += PrintThis.innerHTML;
myWin = window.open("");
myWin.document.write(PrintStyle);
myWin.print();
myWin.close();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<div id="print">
<h1 id="group">
</h1>
<table class="table bordered">
<thead>
<th>Name</th>
<th>Result</th>
</thead>
<tbody>
</tbody>
</table>
</div>
JSFIDDLE of current output
See this example https://jsfiddle.net/qa9wcuft/ there is a break made in a div. It works at least in chrome Version 64.0.3282.167 and Firefox V 61.0.1. The problem is this: https://jsfiddle.net/rz3896se/ it works in firefox but not in chrome. It seems that chrome does not break tables. So my recommendation is to do different tables and put a div in the middle with a break, like this https://jsfiddle.net/8L201zvw/.
Also you are adding this: .Break { page-break-after: always } (.break is better) which is correct to separate pages, but you don't have any element with that class. My suggestion is that you should add class="break" (both in lowercase is better) in the last element you want in the page, in this case, I think is this:
html = '<tr class="break">';
html += '<td><textarea placeholder="textarea..."></textarea></td>';
html += '</tr>';
This does not work in chrome. My suggestion:

Insert the input into mysql

I am a newbie in programming. Excuse my ignorance.
My english is not too good. Hope you understand what I mean in my question.
How can I get the value of id NILAI below and insert into mysql.
html += '<tr>';
html += '<td class="indi" align="center">';
html += row.nis;
html += '</td>';
html += '<td class="indi">';
html += row.nama_siswa;
html += '</td>';
html += '<td>';
html += '<input id="nilai" type="text" placeholder="nilai"/>';
html += '</td>';
html += '</tr>';
I want the input value insert into mysql where col nis in mysql table same with row. nis
I've been trying this, but It's wrong. It just read the value of the first row in input nilai and make a new nis=0.
var data1 = document.getElementById("nilai") ;
var i;
for (i=0;i<data1.length;i++) {
var sql='INSERT INTO nilaitugas(no_tugas, nilai) VALUES ("'+dataid+'","'data1.elements[i]. value+'")';
}
Note: dataid is a variabel from url that I need to input.
you should use this code in javascript to get the value
var data1 = document.getElementById("nilai").value;
USE:
var data1 = document.getElementById("nilai").value; //to get the value in the input tag
var sql='INSERT INTO nilaitugas(no_tugas, nilai) VALUES ("'+dataid+'","'data1+'")';

I want to sort my table column on input value AFTER setting value

Newb here...I have a table I created using the jQuery DataTables plugin. Everything is working as expected BUT I added a column that is an input. I'd like for users to be able to sort this column after putting in their values. It is a ranking system that is using quite a long list of items so they need to be able to sort after entering values so that they can keep track of what numbers they've used up to that point. I am setting my variable to be the input value on keyup but after I set the value, I can't sort the column by clicking on the header. It works for the other columns (from jQuery DataTable plugin). Also, if i hard code some text before if the td (before '+sortRank+') it also works as expected. Why is it not recognizing the values for sorting after I set them with jQuery? Thanks for you help!
$(document).ready(function() {
function GenerateTableFromJson(objArray,objArrayTwo,objArrayThree) {
var tableContent = '<table summary="GFSTechIntake" id="AllRequestsTable" style="width:100%"><thead><tr><th>Submit Priority</th><th>Your Prev Rank</th><th>Current Overall</th><th>Category</th>' + '<th>Status</th>' +' <th>Request Name</th>' + '<th>Problem Statement</th>' + '<th>Business Benefits</th><th>Dept(s)</th></tr></thead><tbody>';
var sortRank = "";
$('input.title').on('keyup',function(){
sortRank = $(this).val();
});
tableContent += '<tr class="allItemsTr">';
if(rank != ''){
tableContent += '<td class="allItemsPriority">'+sortRank+'<input class="title" placeholder=' + rank + ' value='+rank+'></td>';
} else {
tableContent += '<td class="allItemsPriority"><input class="title" placeholder=' + rank + '></td>';
}
tableContent += '<td class="prevRank">N/A</td>';
tableContent += '<td class="currentRank">N/A</td>';
}
return tableContent;
}

Click on href and store data into input box

So I have a table with rows and columns that I loop through and an array which I split by spaces. What I am trying to do is if someone clicks parts[x] that information gets put into an input box.
var parts = data[j][i].split(' ');
tableData += '<td>';
for(x=0; x<parts.length; x++)
{
tableData += '' +parts[x] + ' ' + '';
}
tableData += '</td>';
For instance from below you can see the table that gets outputted now if someone was to press on Software I want Software to go to the top input box on the left which as you can tell already has Software in it for this example the input boxes name=a
Add a click listener to each tag like this:
var parts = data[j][i].split(' ');
tableData += '<td>';
for(x=0; x<parts.length; x++)
{
tableData += '' +parts[x] + ' ' + '';
}
tableData += '</td>';
Then define a handler outside of your tableData generation code like this:
function clickedPart(part){
document.getElementById("input_box").value = part.innerHTML
}
Please note I assumed your input box has the id "input_box". You can change that to whatever you want, but I recommend giving it an ID instead of a name.

Categories