Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Javascript help

Thread Tools
 
Search this Thread
 
Old Mar 23, 2005 | 09:34 PM
  #1  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default Javascript help

Evening chaps.

Here's one for all you javascript types.

Here's an HTML page element:

Code:
<a id="locationareatext" name ="thenewtextarea"/>Text I want to replace</a>
What I want to be able to do, via javascript is to replace the text part of the field, iel change "Text I Want to replace" to anything I like (I'll actually be getting the text from within the JS)

How can I do this?

I am replacing images from JS with no problem, for example:

Code:
<img id="selectionbuttons" src='Images/dvp.png' name ="dvp">
I can change the SRC of the above in JS by simply doing this:

Code:
sourcea = "Images/gardiner_s.png";
document["gardiner"].src = sourcea;
So I guess it can be done, correct?
Reply
Old Mar 23, 2005 | 09:56 PM
  #2  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default

Wise man say "If you use correct search terms, then enlightenment you will find!"

Seems I can do away with the < a > thing, simply specify it as a < div >

then simply have < div ID="nameofitem" >

then in my JS I can use:

Code:
document.getElementById('thedivid').innerText = "the new text";
lovely
Reply
Old Mar 24, 2005 | 09:45 AM
  #3  
SJ_Skyline's Avatar
SJ_Skyline
Scooby Senior
 
Joined: Apr 2002
Posts: 21,922
Likes: 2
From: Limbo
Default

You can also use <span> if you have specific styling/layout associated with divs
Reply
Old Mar 24, 2005 | 09:47 AM
  #4  
SJ_Skyline's Avatar
SJ_Skyline
Scooby Senior
 
Joined: Apr 2002
Posts: 21,922
Likes: 2
From: Limbo
Default

Simple example of changing span contents: (copy and paste into filename.html)

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function displaydatetime()
{
if (!document.layers && !document.all) return;
var today;
var timeLocal;
today = new Date();
timeLocal = today.toLocaleString(); //Convert to current locale.
if (document.layers)
{
document.layers.clockLocal.document.write(timeLoca l);
document.layers.clockLocal.document.close();
}
else if (document.all)
{
clockLocal.innerHTML = timeLocal;
}
setTimeout("displaydatetime()", 500)
}
window.onload = displaydatetime;
</script>
</head>

<body>
<span id=clockLocal style="position:relative;"></span>
</body>
</html>
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
StickyMicky
Computer & Technology Related
3
May 22, 2004 03:02 PM
CodeKey@Lisan
Computer & Technology Related
11
Feb 20, 2004 05:23 PM
RichB
Computer & Technology Related
2
Nov 5, 2003 02:27 PM




All times are GMT +1. The time now is 03:20 PM.