const getitem = () => {
const it = document.getElementsByClassName('byen');
let elems = []
for (let i = 0; i < it.length; i++) {
if (getComputedStyle(it[i]).display === "block") {
elems.push(it[i].textContent);
}
}
return elems;
}
document.getElementById('myField').value == getitem();
var form = document.getElementById("fs-frm");
var item = document.getElementById('bos');
async function handleSubmit(event) {
event.preventDefault();
var status = document.getElementById("but");
var data = new FormData(event.target);
fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json'
}
}).then(response => {
status.innerHTML = "Thanks for your submission!";
form.reset()
}).catch(error => {
status.innerHTML = "Oops! There was a problem submitting your form";
});
}
form.addEventListener("submit", handleSubmit);```
I want the divs inside the div "byen" whose property is block to be the value of the 'myField' input in order to send it to an email.
it's showing Uncaught SyntaxError: Identifier 'getitem' has already been declared
And when I press submit and recieve the email it shows me 'items' with no value taken.
``` <form id="fs-frm" action="https://formspree.io/f/mpzkydvo" method="POST" enctype="multipart/form-data">
<fieldset id="fs-frm-inputs">
<div class="forma">
<div class="tit">
<h1>Buy an item</h1>
</div>
<div class="piccom"><img src="./buy.jpeg" alt="buy"></div>
<div class="containe">
<div class="name">
<label for="full-name">Full Name</label><br><br>
<label for="email-address">Email Address</label><br><br>
<label for="message">Address</label>
</div>
<div class="input">
<input type="text" name="name" id="full-name" required="">
<input type="email" name="_replyto" id="email-address" required=""><br>
<input type="text" name="nname" id="full-address" required=""><br>
<input type="hidden" id="myField" name="itmes" value="" />
<input type="hidden" name="_subject" id="bos" value="Contact Form Submission">
</div>
<div class="submit" id="sendinfo"> <input class="butto" type="submit" value="Submit"></div>
</div>
</div>
</fieldset>
</form>```
I think we’d need to see the HTML that goes along with this in order to help you troubleshoot. Are you sure that there is at least one element with class byen
and that it has display set to block?
Your JavaScript code is probably running before the document has loaded.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.