I am creating a todo project and I am having a problem trying to get the input
values from the user since they are in a different file which I am importing to the current file.
I have a created a different file for creating a div
which has a add task button
and a form
. When the user clicks on the button
it opens a modal
which has the form. The form asks the user for title, description, due-date, and priority. The form has two buttons, confirm and cancel buttons. I want to store the input values in varaibles when the user clicks on the confirm buton after filling the details and use those variables to create the task object
and push it into the array
of task lists.
Since there are going to be several pages I am going to be using this div I thought it would be better if it is in a seperate file and import it wherever I need to use it.
The code for it goes something like this in the addTaskDiv.js
function createButton(){
const addTaskButton = document.createElement("button")
//code that created the button
return addTaskButton
}
function createModal(){
const addTaskModal = document.createElement("dialog")
//code that creates the modal
return addTaskModal
}
function createForm(){
const addTaskform = document.createElement("form")
//code that creates the form
return addTaskform
}
export default function loadAddTaskDiv(){
const div = document.createElement("div")
const addTaskButton = createButton()
const addTaskModal = createModal()
const addTaskForm = createForm()
addTaskModal.append(addTaskForm)
div.append(addTaskButton, addTaskModal)
return div
}
Inside the allTasks.js
which will display all the tasks of the user in a single page
import loadAddTaskDiv from "addTaskDiv.js"
const mainDiv = document.createElement("main");
const addTaskDiv = loadTaskDiv();
mainDiv.append(addTaskDiv)
Now how do I get the values of the input elements from the user into this file and other file as well. I need the input values to create the task object
and push it into the array
of task lists.
I tried to get the values by event
bubbling on change event
but was not able to get the values.
Please help me on how get the values from the user. Sorry if something is not understandable, it was really hard to frame and format this question, please ask if anything is not understandable. I will try to explain as much as I can. Thanks!