Dragstart is undefined, don't understand why

Hello,

The following code results in a “dragStart’ is undefined”, but I don’t understand why.
Any ideas?

	for (var S = 0; S < arrInbound[i][3].length; S++){ 		
		var namesDiv = document.createElement('div');
		namesDiv.id = S;
		namesDiv.draggable = 'true';
		namesDiv.contenteditable = 'true';
		namesDiv.className = "crewNames";
		namesDiv.ondragstart = function(){dragStart(event)
			if(event.target.type=="range")event.preventDefault();
			event.dataTransfer.setData("Text", event.target.id);
			console.log("Dragging...");
		};
		namesDiv.onclick = function(){alert("ytry");};
		namesDiv.innerHTML = arrInbound[i][3][S];
		tagElRight.appendChild(namesDiv)		
	}

Should it have the capital ‘S’ in it? I can’t see it spelt shown like that in the MDN ‘dragstart’ page If not, then it may be viewing it as an undefined variable.

Hello Chrisofarabia,
I tried the S but the problem persists.What about viewing it as an undefined variable.
Not sure how to solve that.

Can you post the section of HTML it’s acting on, or perhaps put up a Codepen or JSFiddle we can look at?

I tried dropping the code into a Codepen window, and then running ‘Analyze JS’ on it. This was the result:

There does seem to be a logic to what’s being reported, so it may be worth separating those functions out of the loop and calling them when required within it. I’m not sure whether that will necessarily help with dragstart being reported as undefined, but it may help clarify what’s happening.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.