Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Dynamic text: modify text by image/link click

Reply
Thread Tools

Dynamic text: modify text by image/link click

 
 
David Housman
Guest
Posts: n/a
 
      02-02-2007
Hello,

The effect i'm trying for:
Tha tthe user clicks an image, and a line of text on the page changes.
I'd like to make it so that this could be done over and over with
different links.
But this isn't working. I think the problem is related to a refresh
not happening, but I'm just learning the javascript ropes.
Thanks in advance for your help.

-Dave
--code follows

*attempt*1*
var avar = 'beforeclick';
//defined in body
//included document.write(avar) in text. it shows up in text, but
doesn't change on click.

function newtext(){
document.write(avar);
return false;
}
<!-- setInterval("newtext()",500);-->
//page doesn't finish loading
newtext();
/this is included in the body of the page.

<a onClick="avar='afterclick'; newtext(); return false;">first link</
a>
//results in a new page with the only element "afterclick"
<a onClick="avar='afterclick'; return false;">first link</a>
//no effect

*Attempt*2*: I also try doing this as an anchor, rather than a global
var.
<a name = "anchor">This is the original text</a>

<a onClick="document.getelementbyid("anchor")='newtex t?'; return
false;">anchorlink</a>
//no effect
<a onClick="anchor='newtext?'; return false;">anchorlink</a>
//no effect

 
Reply With Quote
 
 
 
 
marss
Guest
Posts: n/a
 
      02-02-2007

David Housman wrote:

> The effect i'm trying for:
> Tha tthe user clicks an image, and a line of text on the page changes.
> I'd like to make it so that this could be done over and over with
> different links.


> *Attempt*2*: I also try doing this as an anchor, rather than a global
> var.
> <a name = "anchor">This is the original text</a>
>
> <a onClick="document.getelementbyid("anchor")='newtex t?'; return
> false;">anchorlink</a>
> //no effect
> <a onClick="anchor='newtext?'; return false;">anchorlink</a>
> //no effect


Hi,
Javascript is case sensitive that is why "getelementbyid" not the same
that "getElementById".
If you want to search by id (getElementById) then set id (not name).
<span id="anchor1">This is the original text</span>
<a href="#"
onclick="document.getElementById('anchor1').innerH TML='newtext?';
return false;">anchorlink</a>

or if you want the change occurs after the user clicks on an image:
<span id="anchor1">This is the original text</span>
<img src="someimg.gif"
onclick="document.getElementById('anchor1').innerH TML='newtext?'">

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Modify right click context menus? Hot-Text Computer Support 3 12-01-2010 02:58 PM
How can I modify the name of the text section which is by default".text" LinNan C Programming 2 09-11-2008 01:45 PM
click click click Andy Morrison Computer Support 7 12-20-2007 06:50 AM
How Do I Modify Text In A Cell Based On Button Click dcouture@tycoint.com ASP .Net Web Controls 0 02-08-2007 07:35 PM
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM



Advertisments