JavaScript HELP!!!!!!

RikudoSage

Member
Joined
Sep 4, 2009
Messages
27
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Hi there, I am wanting to create an onclick if statement that outputs the document.write information into a div class that is located in the same page.

here is the code samples:
If statement with document.write:
<script type="text/javascript">
function clickFunc(id){
if (id == songs)
{
document.write("hello world");
}
else if(id == gallery)
{
document.write("hello gallery");
}
}
</script>

onclick function to click it:
<div class = "gallery">
<img src="enterButton.png" id="gallery" onclick="clickFunc(gallery)" />
</div>

the div i want it to go into:
<div class = "mainContent">
<script type="text/javascript">
document.write("clickFunc(id)");
</style>
</div>

everything works except the document.write information going into the div class, it just opens a whole new page.

I hope that makes sense and someone can help me because it is doing my head in!!
 

phikhanh_ctim

Member
Joined
Jul 31, 2008
Messages
3
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
"Hi there, I am wanting to create an onclick if statement that outputs the document.write information into a div class that is located in the same page.", then the codes above should not help...^_^
- document.write will directly output the information to your page(usually body tag) but not a div tag.
- (id == songs) or (id == gallery) --> songs, gallery here are variables not data --> (id == "songs") or (id == "gallery")

you can try this:

<script type="text/javascript">
function clickFunc(id){
var div_mainContent = document.getElementById("mainContent");
if (id == "songs"){
div_mainContent.innerHTML = "hello world";
}
else if(id == "gallery"){
div_mainContent.innerHTML = "hello gallery";
}
}
</script>

<div> <img src="enterButton.png" id="gallery" onclick="clickFunc(this.id)" /> </div>
or
<div> <img src="enterButton.png" onclick="clickFunc('gallery')" /> </div>

The mainContent div tag.

<div id="mainContent">
</div>
 

~Tahir~

Active member
Regular
Joined
Oct 7, 2009
Messages
1,456
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
can u e-mail me the file you are working on ......there is a 90% chance i'll solve your problem....or another best option is go here: and chk out who's expert in javascript
 
Last edited:
Top