Jump to content

[SOLVED] New To Javascript


Northern Flame

Recommended Posts

I hardly program in Javascript and when I do its simple stuff,

but I am stuck on something. I want to have a few links where

if the user click them, something is displayed in a certain div.

Heres a simple sample that I was practicing with so that you

guys can better understand what I am trying to do. Can anyone

help me make this work?

 

<script type="text/javascript">
function secondDiv(){
document.write('This is the default text....');
}
function numberOne(){
function secondDiv(){
document.write('Number One');
}
}
function numberTwo(){
function secondDiv(){
document.write('Number Two');
}
}
</script>
<div style="background-color:#CC0000;">
<a onClick="numberOne()" href="javascript:void(0)">Number One</a><br>
<a onClick="numberTwo()" href="javascript:void(0)">Number Two</a><br>
</div>
<div>
<script type="text/javascript">
secondDiv();
</script>
</div>

 

it displays "This is the default text...." but the text doesnt change,

maybe I am doing this wrong, am I suppose to do it another way

other than changing the function that is being displayed?

Link to comment
Share on other sites

don't use document.write in a function; I have never seen that turn out good. do it like this:

 

 

<script type="text/javascript">
function numberOne()
{
document.getElementById('content').innerHTML='Number 1';
}
function numberTwo()
{
document.getElementById('content').innerHTML='Number 2';
}
</script>
<div style="background-color:#CC0000;">
<a onClick="numberOne()" href="javascript:void(0)">Number One</a><br>
<a onClick="numberTwo()" href="javascript:void(0)">Number Two</a><br>
</div>
<div>
<span id="content">
This is the default text....
</span>
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.