#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    20
    Rep Power
    0

    print text into certen position of page with javaScript


    can i print text on a serten position of an html page, out of a function in the javaScript header area?
    like:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function print_to(value)
    {
    print_obj = value;
    }
    //-->
    </SCRIPT>
    </head>

    <body onload="print_to('hallo"');">

    print_obj

    </body>
    </html>

    should display "hallo"
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    Simple way would be to use document.write.


    <html>
    <head>
    <title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
    <!--
    function print_to(value)
    {
    print_obj = value;
    }
    //-->
    </SCRIPT>
    </head>

    <body>

    <script>
    document.write(print_to('hallo');">
    </script>

    </body>
    </html>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    your func should return the value then...

    Code:
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> 
    <!-- 
    function print_to(value) 
    { 
    return value; 
    } 
    //--> 
    </SCRIPT> 
    </head> 
    
    <body> 
    
    <script> 
    document.write(print_to('hallo');"> 
    </script>
    nah, sorry, this is crap. why have a function that only returns the value passed???


    Code:
    <body>
    ...htmlcode...
    <script> 
    document.write('hallo'); 
    </script> 
    ..htmlcode...
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    20
    Rep Power
    0
    the thing is, i need to be able to change the text depending on what the user does, not only on first load
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    make a layer:
    <div id="layer1" style="position:relative;left:0;top:0">
    </div>

    then you can do
    document.layer1.document.open()
    document.layer1.document.write("new text");
    document.layer1.document.close()
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    <html>
    <head>
    <title>untitled</title>
    <style type="text/css">

    #output {
    position:absolute;
    left:100px;
    top:200px;
    }

    .text {
    font:bold 18px Helvetica,Verdana,sans-serif;
    color:peru;
    }

    </style>
    <script type="text/javascript" language="JavaScript">

    function getElem(id) {
    return document.all ? document.all(id) :
    document.getElementById ? document.getElementById(id) :
    document.layers ? document.layers[id] :
    null;
    }

    function printToPage(id,content,classname) {
    var el = getElem(id);
    if (!el) return;
    if (el.style) {
    el.innerHTML = content;
    if (classname) el.className = classname;
    } else if (el.document) {
    var SPANstr = (classname) ? '<span class="' + classname + '">' : '<span>';
    el.document.write(SPANstr + content + '</span>');
    el.document.close();
    }
    }

    </script>
    </head>
    <body>
    <form>
    <input name="usertext" type="text" size="40" value="Click here and input some text"
    onfocus="if(this.value==this.defaultValue)this.value=''">&amp;nbsp;
    <input type="button" value="Print to Page"
    onclick="printToPage('output',this.form.usertext.value,'text')">
    </form>
    <span id="output"></span>
    </body>
    </html>
  12. #7
  13. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    20
    Rep Power
    0
    i solved it, in ie anyway.
    there i can access a <td></td> by giving a id to it
    <td id="writeHere"></td>
    and the function will look like:
    function write(this)
    {
    writeHere.innerHTML = this;
    }

    if someone has a similar solution working on netscape, would be nice to know
  14. #8
  15. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Posts
    20
    Rep Power
    0
    ps. i don't whant to use layers, because i do not know how much text there will be above.

IMN logo majestic logo threadwatch logo seochat tools logo