JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 1st, 2002, 12:00 PM
lele lele is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 20 lele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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"

Reply With Quote
  #2  
Old March 1st, 2002, 12:11 PM
degsy degsy is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2001
Posts: 1,882 degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level)degsy User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 Days 21 h 19 m 30 sec
Reputation Power: 18
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>

Reply With Quote
  #3  
Old March 2nd, 2002, 11:50 AM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
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...

Reply With Quote
  #4  
Old March 4th, 2002, 03:30 AM
lele lele is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 20 lele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old March 4th, 2002, 12:49 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 189
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()
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #6  
Old March 4th, 2002, 05:51 PM
mrrichardfeder mrrichardfeder is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2001
Posts: 765 mrrichardfeder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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=''">&nbsp;
<input type="button" value="Print to Page"
onclick="printToPage('output',this.form.usertext.value,'text')">
</form>
<span id="output"></span>
</body>
</html>

Reply With Quote
  #7  
Old March 5th, 2002, 06:29 AM
lele lele is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 20 lele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old March 5th, 2002, 06:31 AM
lele lele is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 20 lele User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > print text into certen position of page with javaScript

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap