Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Dynamic text: modify text by image/link click (http://www.velocityreviews.com/forums/t929547-dynamic-text-modify-text-by-image-link-click.html)

David Housman 02-02-2007 03:59 AM

Dynamic text: modify text by image/link click
 
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


marss 02-02-2007 10:41 AM

Re: Dynamic text: modify text by image/link click
 

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?'">



All times are GMT. The time now is 06:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57