I have an input field in HTML:
<input type="text" id="id-name">
I'm generating a random value here:
function rand(length, current) {
current = current || '';
return length ? rand(--length, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".charAt(Math.floor(Math.random() * 60)) + current) : current;
}
and I've defined an empty array:
var sample = sample || [];
After calling the rand() function, I'm trying to push the randomly generated value into the array, along with two other object properties and values:
(function() {
$("#id-name").val(rand(5));
var value = $("#id-name").val();
sample.push({acct:"sample-code", labels:"sample label", trackingcode: value});
})();
I can't get the push method to insert the data into the 'sample' array. I've already tried referencing this topic, but wasn't able to figure out what I'm doing wrong. I don't think it's pushing correctly because when I run:
alert(sample);
all I get is [object Object]