मैं एक धक्का दिया <form>
करने के लिए HTML फ़ाइल जे एस फ़ाइल, और फिर addEventListener इस फार्म के लिए, लेकिन एक त्रुटि का पता चला:
Uncaught TypeError: नहीं पढ़ सकते हैं के गुण अशक्त (पढ़ना 'addEventListener').
मुझे लगता है कि इस वजह से जे एस फ़ाइल से जुड़ा हुआ है सीधे करने के लिए HTML फ़ाइल का मतलब है जो जे एस लोड किया जा सकता से पहले <form>
.
कर सकते हैं किसी को भी कृपया मुझे बताओ कि कैसे इसे हल करने के लिए?
जे एस कोड के नीचे हैं:
// skip to the input fields
$start.addEventListener('click', function(){
$chooseStory.remove()
const inputs = []
inputs.push(`
<form id="form">
<label>Provide The Following Words</lable>
`)
// assign words of stories to names and placeholders of inputs
// the input will automatically loop for as many as the words are
for (const word of stories[$index.value].words) {
inputs.push(`
<input type="text" name='${word}' placeholder="${word}">
`)}
inputs.push(`
<button type="submit" id="submit"> Read Story </button>
<code id="result"></code>
</form>
`)
const inputsField = inputs.join('')
$container.innerHTML += inputsField
})
// retrieve value of the form
const $form = document.getElementById('form')
$form.addEventListener('submit', function(e){
e.preventDefault()
})