473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Feb 2 '07 #1
1 1853

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

Feb 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Treetop | last post by:
I would like to pass text to a popup window to save creating a new html file for each help topic. I would like to have a value for the heading, a value for the text, code for printing the help...
6
by: Litron | last post by:
This question borders between HTML and JS. I would like to have one ALT tag for a Button (IMG src link) when the user creates an onMouseOver event and a second Alt tag displayed onMouseOver if...
3
by: JOSEPHINE ALVAREZ | last post by:
I have this code that I want to use to do a rollover. However, because the company I am doing it for is continually changing the text, I want to be able to use dynamic text to change the text on...
0
by: RSB | last post by:
Hi Every one, i am trying to create a UserControl and i am passing a Array of strings to it. Now based on the Array elements i am creating the LinkButtons Dynamically. I am also passing a Event to...
10
by: Iain | last post by:
Hi All My apologies if this appears to be simple to some of you but I have very little experience of javascript and I cannot work this one out, The code below is a nice piece of code I found...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.