1

I would like to know how can i use/transform this function in order to get work into a INPUT TEXT...

Actually works if target is a DIV, but i would like use it into a INPUT TEXT...

The code i found and i want to use is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


<script src="js/jquery.js" type="text/javascript"></script>
<script language="JavaScript">


 $(document).ready(function (){
  textWrite("THIS'S A MESSAGE, I WOULD LIKE WRITE IT INTO A INPUT TYPE TEXT", '#write', 50);
 });

 function textList()
 {
   max = textList.arguments.length;
   for (i = 0; i < max; i++)
  this[i] = textList.arguments[i];
 }

 function textWrite(txt, selector, time)
 {
  $(selector).empty();
  var x = 0; pos = 0;
  var tl = new textList
    ( 
     txt
    );
  var l = tl[0].length;
  textInterval(selector, tl, l, x, pos, time);
 }

 function textInterval(selector, tl, l, x, pos, time)
  { 
   var interval =
   setInterval(function() {
   $(selector).html(tl[x].substring(0,pos));
   if(pos++ == l) 
    clearInterval(interval);
   }, time);
  }

</script>


<title>Untitled Document</title>
</head>


<body>
<div id="write" /></div>
<input type="text" name="WriteHerePlease" id="WriteHerePlease" />
</body>
</html> 

Thank in advance for all the help you can give me.

2
  • You surely don't want to call that as Java Commented Apr 5, 2015 at 19:07
  • Java ! == javascript Commented Apr 5, 2015 at 19:26

1 Answer 1

1

So in case of input field you just need to set value (val method) instead of innerHTML (html method):

function textWrite(txt, selector, time) {
    $(selector).val('');
    var x = 0;
    var pos = 0;
    var tl = new textList(txt);
    var l = tl[0].length;
    textInterval(selector, tl, l, x, pos, time);
}

function textInterval(selector, tl, l, x, pos, time) {
    var interval = setInterval(function () {
        $(selector).val(tl[x].substring(0, pos));
        if (pos++ == l) clearInterval(interval);
    }, time);
}

Demo: http://jsfiddle.net/epy2xrwL/

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks!, im sorry coz im newbie, but thanks for ur help. Just i would ask something: When the last char is wrote into the text field (so, no more chars to write) how can i set an "alert('i finished');"?
Thanks you so much for your help and time, now i can continue studing about it. =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.