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 23 March 2005, 09:34 PM
  #1  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
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?
Old 23 March 2005, 09:56 PM
  #2  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
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
Old 24 March 2005, 09:45 AM
  #3  
SJ_Skyline
Scooby Senior
 
SJ_Skyline's Avatar
 
Join Date: Apr 2002
Location: Limbo
Posts: 21,922
Likes: 0
Received 1 Like on 1 Post
Default

You can also use <span> if you have specific styling/layout associated with divs
Old 24 March 2005, 09:47 AM
  #4  
SJ_Skyline
Scooby Senior
 
SJ_Skyline's Avatar
 
Join Date: Apr 2002
Location: Limbo
Posts: 21,922
Likes: 0
Received 1 Like on 1 Post
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>
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
StickyMicky
Computer & Technology Related
3
22 May 2004 03:02 PM
CodeKey@Lisan
Computer & Technology Related
11
20 February 2004 05:23 PM
RichB
Computer & Technology Related
2
05 November 2003 02:27 PM



Quick Reply: Javascript help



All times are GMT +1. The time now is 09:10 AM.