Current location: Hot Scripts Forums » General Web Coding » JavaScript » Change plain text


Change plain text

Reply
  #1 (permalink)  
Old 07-21-04, 11:10 AM
Puno Puno is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Spain (EU) Colorado (USofA)
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Question Change plain text

Hi, i need to do a very simple thing.
But sadly it seems to be hard to do...

Any help would be greatly appreciated for I have spent hours on end on this and found no resolution.

I need to change plain text on an HTML exposed page, on the client side, meaning it needs to be done with HTML / Javascript.

Simplest example:
Imagine a page that says: "Text is this."
and has a button that when you press it, you see it say: "Text is that"
The trick is the following:
must not reload the page and must change the text itself, not cover it up with a layer or something like this.

What I am looking for is something like being able to change the 'value' parameter of a 'p' tag or something like that.

Thanks a lot in advance,
=)
__________________
Puno Bleedingrose,
Spectrum 48K BASIC's was cooler, it had a BEEP instruction.
Reply With Quote
  #2 (permalink)  
Old 07-21-04, 01:44 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
To refer to any tag on a page, give it an id:

<div id='myDiv'></div>

then grab it using DHTML

<script>

myTag = document.getElementById('myDiv')

</script>

use the innerHTML/innerText property to manipulate its content.

myTag.innerHTML = "<b>Hello</b>" // Writes a bold Hello in the tag

myTag.innerText = "<b>Hello</b>" // Writes <b>Hello</b> in the tag and treats it as text.

innerHTML/Text is read/write and can be treated like any string in JS.
Reply With Quote
  #3 (permalink)  
Old 07-30-04, 05:21 AM
Puno Puno is offline
Newbie Coder
 
Join Date: Mar 2004
Location: Spain (EU) Colorado (USofA)
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Works like a charm

Thank you a lot!

now playing with the options of having the HTML reevaluated =)
__________________
Puno Bleedingrose,
Spectrum 48K BASIC's was cooler, it had a BEEP instruction.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
how to change text dynamically with image? rabbit51 JavaScript 1 02-23-04 08:35 AM
How to change text dynamically with image? rabbit51 Script Requests 0 02-07-04 12:14 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 10:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.