I have an odd issue where when adding results / events to a user empty entries are added to the array, what is strange is that when I a few at a time it appears to be ok, if I go back and add more this is when the entries appear. See below.
Here is the code for adding the events.
function addEvents(pos) {
document.querySelector('#doupdate').addEventListener('click', function(e){console.log(athletes[pos])
e.preventDefault();
athletes[pos].comps.events.push(evtupdate.value);
athletes[pos].comps.evresult.push(resultupdate.value);
athletes[pos].comps.venue.push(venuup.value)
athletes[pos].comps.edate.push(dateupdate.value);
updateform.reset();
});
initially I used this code below for listing the events, and I thought that it was the for loop, causing the issue, I used that to display each set of results on a new line.
for (let { firstName, lastName, eanum, comps:{events,evresult,venue,edate}
} of athletes)
{ if (firstName===find || eanum===find ) {
for (let i=0; i< events.length; i++)
{let x=i;
document.getElementById('athleteres').innerHTML += `<li id="athleteresults-${dellid++}"
<span class="n" > Name: ${firstName} ${lastName} -- Events: ${events[i]} -- Result:
${evresult[i]}<br><span class ="toggle"> Venue: ${venue[i]} -- Date: ${edate[i]}</span>
<button id= 'b1' onclick="del2(${dellid - 1},${x},${pos})">🚮Del</button><br><hr>`
So I changed it to a forEach and still get the same results.
The next bit of code is where the user clicks on the add event button. The res refers to a filter from search results.
for (let a of res) { pos= athletes.indexOf(a);
document.getElementById('results').innerHTML += `<li id="alc-${nid++}"><span class="n">Loading...
</span> <button id= 'b1' onclick="del(${nid - 1})">🚮Del<button id='b2'
onclick="addEvents(${pos},${nid - 1})"> ➕Events</span></li>`;
document.querySelector(`#results #alc-${nid - 1} .n`).innerText = a.firstName + ' '+ a.lastName +' '+ a.age +' ' + a.club + ' ' + a.eanum
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment