How to interpret HTML code by javascript?

This is my problem:

I'm trying to pass an html string to a <label> by a javascript variable. The problem is that the <br /> tag is not interpreted like a tag by the browser but it is printed on the page. How I can do? This is my code:

function cambiaTesto(idImg) {
      var i = 0;
      var desc = eval('self.document.frm.hdddesc' + idImg + '.value');
       var arr = self.document.frm.getElementsByTagName("label")
      while (i<arr.length ) {
            if (arr[i].id == "desc" ) {
                  arr[i].childNodes[0].NodeValue = desc;
            }
      i++;
      }
}

this code is called when I click on an image (the id is passed)
The self.document.frm.hdddesc[id of Image].value contains the text associated to the images
This is the value that I pass:

<input name="hdddesc<%=rsFoto("idFoto")%>"  type="hidden"  value=<%=replace(replace(UCase(rsFoto("descrizione")),chr(34),"\"),vbcrlf,"<br />" )%> />

If the value of input is an HTML text (ex. HALLO WORLD<br />I' M EUGENE ) the HTML tag are not interpreted like tag but like text plain ( this is printed on the page: "HALLO WORLD<br />I' M EUGENE")

fbenveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

justinbilligCommented:
change your function to look like this

change your function to look like this


var i = 0;
var desc = self.document.frm.elements[ "hdddesc" + idImg" ].value;
var arr = self.document.frm.getElemetnsByTagName( "label" );

// Loop through the array
for( i = 0; i < arr.length;




function cambiaTesto( idImg )
{
      // Variables
      var intIndex = 0;
      var strDescription = self.document.frm.elements[ "hdddesc" + idImg ].value;
      var aobjLabels = self.document.getElementsByTagName( "label" );

      // Loop through the labels
      for( intIndex = 0; intIndex < aobjLabels.length; intIndex++ )
      {
            // Is this a description?
            if( aobjLabels[ intIndex ].id == "des" )
            {
                  // Yes, set the html
                  aobjLabels[ intIndex ].childNodes[ 0 ].innerHTML = strDescription;
            }
      }
}
0
justinbilligCommented:
err sorry i messed up my post

change your function to look like this


function cambiaTesto( idImg )
{
     // Variables
     var intIndex = 0;
     var strDescription = self.document.frm.elements[ "hdddesc" + idImg ].value;
     var aobjLabels = self.document.getElementsByTagName( "label" );

     // Loop through the labels
     for( intIndex = 0; intIndex < aobjLabels.length; intIndex++ )
     {
          // Is this a description?
          if( aobjLabels[ intIndex ].id == "des" )
          {
               // Yes, set the html
               aobjLabels[ intIndex ].childNodes[ 0 ].innerHTML = strDescription;
          }
     }
}
 
 
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.