Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Design

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 12-10-2007, 01:32 AM
New kid on the block
 
Join Date: Oct 2007
Location: Malaysia
Posts: 2
Rep Power: 0
calvin1cal is on a distinguished road
Unhappy Help! InnerHTML Problem (javascript)

Hi, I'm having some problem with innerHTML. I was able to enter content into innerHTML with javascript. But how do I clear the innerHTML content and enter another new content? Below is the example problem

--------------------------------------------------------------------------

<div id="testing"></div>

<script type="text/javascript">
function show1() {
document.getElementById('testing').innerHTML = "Hello World";
}
function show2() {
document.getElementById('testing').innerHTML = "Goodbye World";
}
</script>

<input type="button" value="show1" onmousedown="javascript:show1();" />
<input type="button" value="show1" onmousedown="javascript:show2();" />


--------------------------------------------------------------------------

When I try it, it ended up showing "Hello WorldGoodby World" if I press "show1" then press "show2". How can I clear the content before enter new content in innerHTML?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2007, 10:58 AM
goolie's Avatar
Senior Webmaster
 
Join Date: Apr 2007
Location: penang
Posts: 792
Rep Power: 32
goolie is on a distinguished road
Send a message via MSN to goolie Send a message via Skype™ to goolie
r u sure or not?? but i tried it with ur ok..it works fine..no problem at all..

after i click show1 button it will display Hello World...then when click on show2 button..it will display Goodbye World...

u may try ur code again, try paste ur code into notepad and save as abc.html at some place(like destop)...then the IE file will appear there, try open it and play its...i thnk ur code will not have any problem...
.......
.........
<div id="testing"></div>

<script type="text/javascript">
function show1() {
document.getElementById('testing').innerHTML = "Hello World";
}
function show2() {
document.getElementById('testing').innerHTML = "Goodbye World";
}
</script>

<input type="button" value="show1" onmousedown="javascript:show1();" />
<input type="button" value="show1" onmousedown="javascript:show2();" />
..
....
__________________
Ideas For Financial Freedom

http://imDavidLee.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2007, 06:27 PM
New kid on the block
 
Join Date: Oct 2007
Location: Malaysia
Posts: 2
Rep Power: 0
calvin1cal is on a distinguished road
Smile

thanks.....I think it was somewhere wrong....the original code is not this long...
it was about 2 page long so I think somewhere might go wrong...anyway, I used a different code to change things by using document.url and pass value from url.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2007, 10:00 PM
mysticmind's Avatar
Super Moderator
 
Join Date: Jun 2001
Location: Mystic Kingdoms
Posts: 2,606
Rep Power: 141
mysticmind will become famous soon enough mysticmind will become famous soon enough
Send a message via Yahoo to mysticmind
<div id="testing"></div>

what was that?
__________________
Personal's Blog! - Malaysian Artist!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-11-2007, 09:52 AM
goolie's Avatar
Senior Webmaster
 
Join Date: Apr 2007
Location: penang
Posts: 792
Rep Power: 32
goolie is on a distinguished road
Send a message via MSN to goolie Send a message via Skype™ to goolie
it is unique id for the element..the purpose is to retriev the string value identifying the object.
__________________
Ideas For Financial Freedom

http://imDavidLee.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 05-11-2007, 10:03 AM
mysticmind's Avatar
Super Moderator
 
Join Date: Jun 2001
Location: Mystic Kingdoms
Posts: 2,606
Rep Power: 141
mysticmind will become famous soon enough mysticmind will become famous soon enough
Send a message via Yahoo to mysticmind
No lah!.. it's a blank div.

I think. all those code (the form and button) should be INSIDE that div
__________________
Personal's Blog! - Malaysian Artist!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-11-2007, 04:14 PM
goolie's Avatar
Senior Webmaster
 
Join Date: Apr 2007
Location: penang
Posts: 792
Rep Power: 32
goolie is on a distinguished road
Send a message via MSN to goolie Send a message via Skype™ to goolie
i thnk the div id and the getElementByID should be same("testing")..this is to retrieve the string value like 'Hello world' and 'Goodbye World'...if not same then i would not display the text..
__________________
Ideas For Financial Freedom

http://imDavidLee.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 17-11-2007, 12:57 AM
tm89lee's Avatar
Inspired Webmaster
 
Join Date: Mar 2006
Location: Kuantan
Posts: 182
Rep Power: 33
tm89lee is on a distinguished road
Send a message via MSN to tm89lee Send a message via Yahoo to tm89lee
Quote:
Originally Posted by mysticmind View Post
<div id="testing"></div>

what was that?
shouldnt your closing div tag be at the bottom? well...sounds like it..
__________________
Quote:
DonT ShoW to ShOw pls ppl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 20-11-2007, 09:42 AM
goolie's Avatar
Senior Webmaster
 
Join Date: Apr 2007
Location: penang
Posts: 792
Rep Power: 32
goolie is on a distinguished road
Send a message via MSN to goolie Send a message via Skype™ to goolie
i never tried it b4..bu i thnk that if u put div tag at the bottom..i still can work
__________________
Ideas For Financial Freedom

http://imDavidLee.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript + php tenuk Website Programming 3 11-12-2006 09:32 AM
HTML & JavaScript marcoenie Website Design 8 15-02-2006 12:03 PM
import javascript honeyz Website Design 1 27-09-2005 10:09 AM
javascript question kelly001 Website Design 0 22-07-2003 01:20 AM
Just some questions about Javascript ngaisteve1 Website Design 1 13-02-2003 04:08 PM



All times are GMT +8. The time now is 12:46 PM. Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0 vBulletin skin by ForumMonkeys.com.


WebmasterMalaysia.com is Proudly Hosted by Exabytes Semi Dedicated Server.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58