PDA

View Full Version : Innerhtml help



Crisp
Nov 25th, 2009, 11:40 PM
Hey, for some reason, this isn't working because of the src="images/edit.png" attribute.

Here is my code:

<a href="#" onclick="change('HEYYY')"><img src="images/edit.png" alt="Edit" id="edit1" /></a>

Javascript (External)

function change(message)
{
document.getElementById('edit1').innerHTML = '<input type="text" value="'+message+'" />';
}

It does nothing. But if I take the src attribute out, it works fine.
Any help?
Thanks.

TinyScript
Nov 25th, 2009, 11:53 PM
<script>

function change(message)
{
document.getElementById('edit1').innerHTML = '<input type="text" value="'+message+'">';
}



</script>


<a href="#" id="edit1" onclick="change('Enter New Value')"><img src="images/edit.png" alt="Edit" ></a>


Is this what you needed?

mrhoo
Nov 26th, 2009, 12:25 AM
You are trying to insert an input inside an image element,
but an <img /> is an empty element- it cannot contain any children.
There is no </img> end tag to contain anything.

Crisp
Nov 26th, 2009, 12:47 AM
@Tiny, Yes! Thanks!
@Mr, I see, lol.
Thanks dude.