Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: innerHTML


Message #1 by "Joel Wickard" <joel.wrox.list@l...> on Thu, 26 Jul 2001 06:38:51 -0500
Actually I did just go adding elements, or one element rather to the tree.
Instead of just tring to add option elements in string form, I tacked the
select tag to the string, which was originally contained within a div, so
instead of trying to use innerhtml on the select tag, I used it on the div
tag instead.  worked fine.

----- Original Message -----
From: "Albetski, Allan" <aalbetski@t...>
To: "javascript" <javascript@p...>
Sent: Friday, July 27, 2001 10:01 AM
Subject: [javascript] RE: innerHTML


>
> You can't just add new elements to the DOM Tree using innerHTML
statements.
> Even though they may appear to be only strings to you, they are actually
> nodes in a tree. To do what you want you need to use the correct syntax
for
> adding elements to the Document Object Model (DOM) tree.
>
> Try this, setup a shell for your select tag: <Select id="cboLOB"></Select>
> (I use this ID later on in the example, you can call it anything you want)
>
> Then populate with options. Here's an example of mine that reads values
from
> a database:
> The OpenADOConnection and CloseADOConnection functions are not shown here
as
> they really don't relate to this question.
>
> Hope this helps some, even if just an understanding that you are really
> dealing with a tree-structure inside of the DOM and not a simple string.
>
> function GetLinesOfBusiness()
> {
> var sLOBCode
> var sLOBDesc
> //
> // This function retrieves the Lines Of Business Codes from the
> database
> //
> var sSQL="SELECT LOBs.[LOB Code] AS fCODE, LOBs.[Line of Business]
> AS fDESC From LOBs "
> sSQL+= " ORDER BY LOBs.[Line of Business]"
>
> OpenADOConnection()
> var adoRecordSet = new ActiveXObject("ADODB.Recordset")
> adoRecordSet.Open(sSQL,adoConnection)
> do
> {
> sLOBCode = adoRecordSet.Fields('fCODE')
> sLOBDesc = adoRecordSet.Fields('fDESC')
> //
> // Build the option tags of the select control
> //
> var oOption = document.createElement("Option")
> oOption.value=sLOBCode
> oOption.innerText = sLOBDesc
> cboLOB.insertBefore(oOption,null)
> adoRecordSet.MoveNext
> }
> while (!adoRecordSet.EOF)
> adoRecordSet.Close
> CloseADOConnection()
> }
>
>
> -----Original Message-----
> From: Joel Wickard [mailto:joel.wrox.list@l...]
> Sent: Thursday, July 26, 2001 7:39 AM
> To: javascript
> Subject: [javascript] innerHTML
>
>
> Hello Everyone,
>
> I have a select box
>
> <select id="select_box">
> </select>
>
> when I try to set the innerHTML property it does nothing.
> new_value = "<option>hello</option><option>everyone</option>"
> document.all.select_box.innerHTML = new_value;
>
> I can use alert to display the value of the innerHTML property before and
> after I set it, and it shows nothing before, after I set it to the new
> value, it displays the new value, but nothing changes in the select box on
> the screen.
> am I using this right?


  Return to Index