I have a webpage the currently types text# (automated with code below) into a text box ta#.
Problem #1) When I run the function, I can only figure out how to make it type into all textboxes at the same time. -- I want it to type naturally (1 by 1, with a slight delay between each) into each textbox. How can I accomplish this?
Problem #2) What is the proper way to shut off/clear this automated typing once the user clicks/selects a text box?
var text1 = "Type this into textbox usr"; var text2 = "Type this into textbox usr2"; var ta1 = document.getElementById("usr"); var ta2 = document.getElementById("usr2"); function type(string,element){ (function writer(i){ if(string.length <= i++){ element.value = string; return; } element.value = string.substring(0,i); if( element.value[element.value.length-1] != " " )element.focus(); var rand = Math.floor(Math.random() * (100)) + 140; setTimeout(function(){writer(i);},rand); })(0) } type(text1,ta1); type(text2,ta2); // This doesnt work right.
Promises would workelement.value = stringyou don't actually need promises, you can do it with a callback. Try putting in a callback (with delay if you want). Then you should be able to make it work with something liketype(text1,ta1, type.bind(null,text2,ta2))assuming you wrote it likefunction type(string,element, callback){