1

I have javascript peace of code that I load into my custom template page. It is quiz application based on pure javascript and I keep the questions with answers inside the array object. The thing is that I want to make that the user could add his own questions through admin dashboard instead of going straight to javascript file and manipulating the code there. I already wrote javascript function which when called with passed arguments will add more questions to the quiz. Now I want to create custom top-level admin menu with some custom meta box to insert the question which then will be sent to javascript function argument. Some of my JS code:

This is the array of questions I want to populate from admin dashboard:

let thequestion = [
  new Question("What is a typical danish breakfast?", ["Pork", "Pork1", "Pork2"], "Pork"),
  new Question("Is NodeJS is a front end or back end framework?", ["Back end", "Front End"], "Back end"),
  new Question("Is JAVA object oriented language?", ["Yes", "No"], "Yes")
]

the function to call from admin dashboard with arguments retrieved from custom fields/meta boxes:

var answers_args = ["yeah", "jo"];

function insertQuestion(question, answers, correct) {
  thequestion.push(new Question(question, answers, correct));
}

insertQuestion("Whats up?", answers_args, "yeah");

My question is: what is the right way to talk to my javascript from admin dashboard? Should I be using ajax or anything else? I'm totally new to this and have no idea how wordpress can talk to javascript. Any ideas? Does my logic with making custom admin menu page makes any sense in this case scenario?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.