SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot musicman77's Avatar
    Join Date
    Dec 2005
    Location
    New Orleans, Louisiana, USA
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    changing from form to div

    Hello,

    I don't know much about JS, but I found this useful script which changes text over a period of time. However it displays the text in a form, not a div. Is there anyway, I can make it display in a div instead?

    Code:
     
     
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    var CurrentMsg = 'A1 JavaScripts welcomes you to its website';
    function update(msg) {
    var pad_str="";
    n = msg.length;
    if(n<72) {
    pad = (73-n)/2;
    for(var i=0; i<pad; i++) {
    pad_str+=" "; 
    }
    }
    CurrentMsg = pad_str + msg;
    document.messages.field.value = CurrentMsg;
    clearTimeout(timer);
    timer = setTimeout("idleMsg()",2500);
    }
    function MakeArray(n) {
    this.length=n;
    for(var i = 1; i<= n; i++) {
    this[i] = "";
    }
    return(this);
    }
    var index = 1;
    var notice_num = 9;
    var notices = new MakeArray(notice_num);
    notices[1] = "A1 JavaScripts welcomes you to its website";
    notices[2] = "Thank you for visiting, I hope you find what you are searching for";
    notices[3] = "This is the example of the form text javascript.";	 notices[4] = "Each message can be adjusted either in speed, or content";
    notices[5] = "The length of the message box can also be personalized to fit your needs.";
    notices[6] = "More lines can be easily added to this script";
    notices[7] = "Simply copy and paste the code into your page"; 
    notices[8] = "Enjoy these scripts, and good luck with your site";
    var timer = setTimeout('idleMsg()',1500);
    function nochange() {
    document.messages.field.value = CurrentMsg;		
    }
    function idleMsg() {
    update(notices[index++]);						 
    if(index>notice_num) { 
    index=1; 
    } 
    }
    // End -->
    </SCRIPT>
     
    <!-- --><center><font face="Helvetica">
    <FORM name="messages" onSubmit="return false">
    <input type="text" name="field" size=40 style="width:445" value=" " onFocus="self.status='This is a JavaScript information data field'; return true" onChange="nochange()">
    </FORM></font>
    </CENTER>
    <!-- -->
    David A. -- Hand coder
    Get Firefox


  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, just change all instances of document.messages.field.value to document.getElementById('messages').innerHTML

    That is if the id of the div is 'messages'.
    Saul

  3. #3
    SitePoint Zealot musicman77's Avatar
    Join Date
    Dec 2005
    Location
    New Orleans, Louisiana, USA
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.
    David A. -- Hand coder
    Get Firefox



Bookmarks

Posting Permissions

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