The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
print text into certen position of page with javaScript
Discuss print text into certen position of page with javaScript in the JavaScript Development forum on Dev Shed. print text into certen position of page with javaScript JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 1st, 2002, 12:00 PM
|
|
Member
|
|
Join Date: Mar 2001
Posts: 20
Time spent in forums: < 1 sec
Reputation 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"
|

March 1st, 2002, 12:11 PM
|
|
|
|
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>
|

March 2nd, 2002, 11:50 AM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
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...
|

March 4th, 2002, 03:30 AM
|
|
Member
|
|
Join Date: Mar 2001
Posts: 20
Time spent in forums: < 1 sec
Reputation 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
|

March 4th, 2002, 12:49 PM
|
|
Contributing User
|
|
Join Date: Oct 2000
Location: Back in the real world.
|
|
|
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()
|

March 4th, 2002, 05:51 PM
|
|
Contributing User
|
|
Join Date: Nov 2001
Posts: 765
Time spent in forums: 3 m 45 sec
Reputation Power: 12
|
|
|
<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=''">
<input type="button" value="Print to Page"
onclick="printToPage('output',this.form.usertext.value,'text')">
</form>
<span id="output"></span>
</body>
</html>
|

March 5th, 2002, 06:29 AM
|
|
Member
|
|
Join Date: Mar 2001
Posts: 20
Time spent in forums: < 1 sec
Reputation 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

|

March 5th, 2002, 06:31 AM
|
|
Member
|
|
Join Date: Mar 2001
Posts: 20
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
ps. i don't whant to use layers, because i do not know how much text there will be above.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|