954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Javascript appendchild executing twice

function displayResult()
{
var  damn = document.getElementById("textyar").value;
document.getElementById("oneforty").innerHTML = damn;
var newDIV = document.createElement('div');
newDIV.className = "tweets";
var newspan =document.createElement('span');
newspan.className = "imagespanleft";
var img = document.createElement("IMG");
img.className="image";
img.src = "tweets/me.jpg";
newDIV.innerHTML = document.getElementById('textyar').value;  
document.getElementById('leftmaindiv').appendChild(newDIV).appendChild(newspan).appendChild(img); 
}

this is the code , i m trying to create an interface like twitter where u put in text box and tweet appears below in
problem is it is creating two divs instead of one , i tried insertbefore() as well but same behaviour
plz ask any questions if u r still not clear

learner guy
Light Poster
26 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

displayResult() seems OK. It creates one new div, <div class="tweets"> with some content, and puts it in leftmaindiv.

If two divs are created then it seems likely that displayResult() is called twice.

In other words the problem probably lies elsewhere, ie. wherever displayResult() is called.Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

thnx for reply , u r right the problem was with form i was calling it in , thnx again :)

learner guy
Light Poster
26 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You