php - Javascript copy & symbol from div to input malfunction -


i cannot find answer question...

the problem. javascript copying text div input (textbox), fails copy & &, , copies &. see code plus example.

i have following code (on different pages, simplify put here):

input want text copied.

<input name="artist" id="txtartist" type="text" placeholder="introduce artist" /> 

div text copied from. data populated sql database.

<div id="art0"><div onclick="copytext(0)">mumford & sons</div></div>' 

the function fails...

function copytext(rowid){     var content = document.getelementbyid('art'+rowid).innerhtml.replace(/<\/?[^>]+(>|$)/g, "\n");     document.getelementbyid("txtartist").value = document.getelementbyid('art'+rowid).innerhtml;     document.getelementbyid("txtartist").value = content; } 

expected result inside textbox: mumford & sons

actual result inside textbox: mumford &amp; sons

any please?

thank all!!

use .textcontent instead of .innerhtml:

var content = document.getelementbyid('art'+rowid).textcontent; 

http://jsfiddle.net/4tr5t/1/

note .textcontent not supported ie 8 , lower, if unfortunate, test , use .innertext instead.

var prop = 'textcontent' in document.body ? 'textcontent' : 'innertext',     content = document.getelementbyid('art'+rowid)[prop]; 

http://jsfiddle.net/4tr5t/2/


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -