Question: Pass variable from Javascript file to Express/Node file

Question

Pass variable from Javascript file to Express/Node file

Answers 0
Added at 2016-12-19 21:12
Tags
Question

Basic File Structure:

public
    javascript
        script.js
app.js
    views
        startprofile.ejs

I'm using the startprofile.ejs which also uses the script.js, I have an array of objects in the script.js and need to pass it to my app.js to edit information on a User model.

Not sure how to approach this.

Code in script.js, currently logs strings in console that I need to pass to app.js:

var lis = document.getElementsByClassName("notSkill");

for (i = 0; i < lis.length; i++) {
    lis[i].addEventListener("click", function() {
        if(this.className == "skill") {
            this.className = "notSkill";
        } else {
            this.className = "skill";
        }
    });
}

var save = document.getElementById("save");
save.addEventListener("click", function() {
    var skills = document.getElementsByClassName("skill");
    for(i = 0; i < skills.length; i++) {
        console.log(skills[i].textContent)
    }
})
Answers
Source Show
◀ Wstecz