Phil Cho Phil Cho - 6 months ago 61
Javascript Question

How to pass inputs from one function to another using .apply method?

For my assignment, I have to read 3 inputs. Once I have the input, I have to pass them as arguments to the addNewPost function. I understand that I have to use the .apply function, however, I am confused on how to do this even after looking at various sources online.

function handleFormSubmit() {

var username = document.getElementById("input-username").value,
password = document.getElementById("input-password").value,
picture = document.getElementById("input-picture").value;

addNewPost.apply(this, arguments);
}

function addNewPost(username, img_src, caption) {

}


Am I correctly reading the inputs, and if I am, how do I pass them as arguments to addNewPost?

KKK KKK
Answer Source

If using apply is not a requirement, you can simply pass them into the function;

addNewPost(username, password, picture);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download