Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    189
    Thanks
    38
    Thanked 3 Times in 3 Posts

    javascript - One letter appear at a time problem

    Hey all,
    Below is a script that forces text to appear letter by letter. The problem is I want the actual letters to be a link at the same time and I don't want to display the text in a form tag, which it currently is in now. Rather I would like to display it in an h1 tag. Problem is, despite still referencing "msgform" in the html as an id selector of an h1 element and changing the code "self.document.msgform.elements[0].value=outMsg;" to "document.getElementById("msgform").value=outMsg;", it generates no effect at all. So I'm not exactly sure what I'm doing wrong as I try to display it in an h1 element and also as a link. Any help is greatly appreciated!

    Code:
    <script  language="javascript"  type="text/javascript">
    
    var outMsg = "";
    var i = 0;
    var lineNo = 1;
    var timerDM=null;
    var msg = " ";
    function araVob() {
    }
    var ScreenLine = new araVob();
    ScreenLine[1]  = "Opportunities!"
    
    var msgNum = 1;          
    var msgCnt = 1;          
    var typeSpeed = 70;       
    var pageLen = 1;          
    var delay=typeSpeed;
    var r = 0;
    var cr="\r\n"
    if ("3" <=navigator.appVersion.charAt(0)) {
    var cr="\n"
    }
    for (x = 1; x<=(msgCnt); x++) {
      ScreenLine[x] = ScreenLine[x] + cr;
    }
    msg = ScreenLine[1];
    
    function DisplayMsg() {
      if (msg.length <= i || msg.charAt(i) == "\f") {
        r=i;
        i=0;
        ChangeMsg();
      }
      outMsg = outMsg + msg.charAt(i);
      i++;
      if (msg.charAt(i) == "\f" || (lineNo == pageLen && i==msg.length)) {
        delay = 4000; }
      else {
      if (msg.charAt(i) == cr && msg != " "+cr) {
        delay = 2000; }
      else {
        delay = typeSpeed; }
      }
      self.document.msgform.elements[0].value=outMsg;
      timerDM = setTimeout("DisplayMsg()",delay);
    }
    
    function ChangeMsg() {
    msgNum++;
    if (msgCnt < msgNum) {
       msgNum = 1;
    }
    lineNo++;
    if (pageLen < lineNo || msg.charAt(r) == "\f") {
      outMsg=ScreenLine[msgNum].charAt(i);
      i++;
      lineNo = 1;
    }
      msg = ScreenLine[msgNum];
    }
    
    window.onload = DisplayMsg;
    window.onunload = quitDisplay;
    // -->
    </script>
    <FORM NAME= "msgform" ACTION=" " style="position:absolute;">
         <TEXTAREA style="border:none;">
              </TEXTAREA>
    
    </FORM>
    Last edited by johnmerlino; 11-07-2009 at 02:45 AM. Reason: wrong code


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •