D
David Housman
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")='newtext?'; return
false;">anchorlink</a>
//no effect
<a onClick="anchor='newtext?'; return false;">anchorlink</a>
//no effect
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")='newtext?'; return
false;">anchorlink</a>
//no effect
<a onClick="anchor='newtext?'; return false;">anchorlink</a>
//no effect