Click to See Complete Forum and Search --> : opening text in div


calmamerican
09-25-2003, 12:12 AM
basicly what i have is

<div><a>1</a><a>2</a><a>3</a><a>4</a></div>
<div>text</div>


what i would like is that when you click on a link it changes the text in the second div without reloading the entire page

i am assuming that javascript would be the best way to do this

i tried searching for this but i didnt find anything with my searches

thanks

Khalid Ali
09-25-2003, 12:27 AM
were you asking for something like this


<div>
<a href="#" onclick="changeText(this);">1</a>&nbsp;&nbsp;
<a href="#" onclick="changeText(this);">2</a>&nbsp;&nbsp;
<a href="#" onclick="changeText(this);">3</a>&nbsp;&nbsp;
<a href="#" onclick="changeText(this);">4</a>&nbsp;&nbsp;
</div>
<div id="div_1">text</div>
<script type="text/javascript">
function changeText(obj){
document.getElementById('div_1').innerHTML=obj.firstChild.nodeValue;
}
</script>

calmamerican
09-25-2003, 02:24 AM
i am a relative noob to javascript

i think that is what i want

but when i cut and past that into a head of a blank html page then links and the word text come up

but when i click the links nothing happens

*edit*

that is what i wanted

the next question is how do i make it something other than the number

example

if i click on 1 i want it to say hello and 2 goodbye 3 etc

how do i change what the messages are?

Khalid Ali
09-25-2003, 08:10 AM
you do not put all of the code in the head....only the code that is withing the
<script ....>

.....

</script>

tags goes in head section.
For this examples sake you don't have to do that either.Just put all of the code in the body of the page and you are all set.

calmamerican
09-25-2003, 11:45 AM
i got the script to work but now i want it to show something other than the number

how do i do that?

Khalid Ali
09-25-2003, 02:35 PM
Just change the value in between the <a>value to be changed</a>

anchor tags