?
Solved

How to interpret HTML code by javascript?

Posted on 2004-11-17
4
Medium Priority
?
190 Views
Last Modified: 2010-08-05
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")

0
Comment
Question by:fbenve
  • 2
2 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 12606382
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
 
LVL 15

Accepted Solution

by:
justinbillig earned 1000 total points
ID: 12606397
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question