I’m trying to build a practice site that will allow the user to add ‘tiles’, either text or images to a page using DOM manipulation. I need to measure the length of text inputs to determine what class to give to each new ‘tile’. The problem is that no matter what I seem to try I can not get the function that gets and writes the value to a tile to read what is in the input field correctly the first time. It always just reads and writes the default value of the input field on the first click then works after.
// variable to hold the text submission element
let textEntryBox = document.getElementById('textUpload').value;
let textEntryLength = document.getElementById('textUpload').value.length;
// variables to create new text tiles
let textTile = document.createElement("span");
let node = document.createTextNode(document.getElementById('textUpload').value);
// checks text element size
let newTileSize = textEntryBox.length;
function checkTextSize() {
inputSize = textEntryBox.value.length;
newTileSize = inputSize;
};
// creates new text tile
function createNewTextTile() {
var elementToAppend = document.getElementById('one');
if (submitState == 'text') {
node = document.createTextNode(newTileSize); //document.getElementById('textUpload').value);
textEntryBox = document.getElementById('textUpload');
var builtNode = textTile.appendChild(node);
var x = document.getElementById('one').appendChild(builtNode);
}
and the html it is attached to
<div class='textUploadHolder'>
<label class='textUpload' for='textUpload'>Upload Text:</label>
<input class='textUpload' id='textUpload' type='text' name='textUpload' onclick="checkTextSize() "onchange="checkTextSize()" onblur="checkTextSize()"></input>
</div>
any help is greatly appreciated