javascript - Text Input Value sometimes does't change even though it thows no errors, and seems to work -


so have simple program change value of input field every time blur it. logs used values in array, use array check if it's been used. practically works intended, after few tries return true , logs, yet value wont change.

updated code:

var dftvalue = ['freddy grocer', 'jack fiddler', 'cane sheep herder', 'arnold fish monger', 'luke car salesman', 'josh tailor', 'carol baker', 'tiara nacho vendor', 'example@email.com', 'your message here.'];  var logused =  new array(); //create new array log used indexs  function setdftvalue() {    var newval = dftvalue[math.floor(math.random() * 7)];    if (logused.indexof(newval) == -1) {      this.value=newval;      logused.push(newval);      console.log(logused);    } else if (logused.indexof(newval) >= 0) {      setdftvalue();    }    if (logused.length == 8) {       (i=0; i<=7; i++){         logused.pop();       }    } } document.getelementbyid('formname').onblur=setdftvalue; 

jsfiddle https://jsfiddle.net/e5pdz37e/8/

your approach unnecessarily complicated. @ high level recommend approach that's more this:

function setdftvalue() {     if (index === (dftvalue.length - 1)) {         // shuffle names array         index = -1;     }      input.value = dftvalue[++index]; } 

this way won't need use recursion , make unnecessary function calls. , time you'll need randomize when you've used of available names.

here's working example: http://jsfiddle.net/bvaughn/163mqdel/

original answer

after few invocations, function fill logused array, @ point calling again nothing. actually, worse nothing - recursively call without end.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -