I'm new to programming/web development, learning it in community college, so you'll probably have to explain your answers to me as if i'm an idiot. Anyway, my current assignment in a class i'm taking is to build upon a basic app that times a staff meeting and calculates the cost said meeting based on the participants' salary per second. What i've learned, at a basic level, how to take the client's input (through text boxes) and save them in a database to be called upon and displayed later, but i can't figure out how to do that with objects in javascript. My point in doing that is to save the cost of the meeting, as well as participants, so that the client can display it later.
Here is the javascript code:
window.onload = function() {
var startTimestamp = 0;
var endTimestamp = 0;
var startTimestampButton = document.getElementById('start-timestamp');
var startTimestampElement = document.getElementById('start-timestamp-value');
startTimestampButton.onclick = function() {
startTimestamp = Date.now();
startTimestampElement.innerHTML = startTimestamp;
}
var endTimestampButton = document.getElementById('end-timestamp');
var endTimestampElement = document.getElementById('end-timestamp-value');
endTimestampButton.onclick = function() {
endTimestamp = Date.now();
endTimestampElement.innerHTML = endTimestamp;
}
var selectElement = document.getElementById('selected-staff');
for (var username in data)
{
var obj = data[username];
var opt = document.createElement('option');
opt.value = obj.SAL_SECOND;
opt.innerHTML = obj.FIRST_NAME + " " + obj.LAST_NAME;
selectElement.appendChild(opt);
}
var pageHeading = document.getElementById('page-heading');
var totalSalaryPerSecondForSelectedStaff = 0;
selectElement.onchange = function() {
totalSalaryPerSecondForSelectedStaff = 0;
for(var i=0; i < selectElement.length; i++)
{
if (selectElement.options[i].selected)
{
totalSalaryPerSecondForSelectedStaff += Number(selectElement.options[i].value);
}
}
//pageHeading.innerHTML = totalSalaryPerSecondForSelectedStaff;
};
window.setInterval(function() {
if (totalSalaryPerSecondForSelectedStaff > 0 && startTimestamp > 0 && endTimestamp === 0)
{
var currentTimestamp = Date.now();
**var meetingCost = totalSalaryPerSecondForSelectedStaff * ((currentTimestamp - startTimestamp) / 1000);**
if (meetingCost < 10)
{
pageHeading.innerHTML = "☺ $" + totalSalaryPerSecondForSelectedStaff * ((currentTimestamp - startTimestamp) / 1000);
}
else
{
pageHeading.innerHTML = "☹ $" + totalSalaryPerSecondForSelectedStaff * ((currentTimestamp - startTimestamp) / 1000);
}
console.log('Start Timestamp: ' + startTimestamp);
console.log('Current Timestamp: ' + currentTimestamp);
console.log('Total Salary Per Second for Selected: ' + totalSalaryPerSecondForSelectedStaff);
}
}, 1000);
I couldn't figure out how to get to "var meetingCost" in a separate php file, or how to just input it to the database in the same file.
Would really appreciate the help! This is kind of over my head right now!