views:

487

answers:

3

Hello:

I am using the following JavaScript function:

function Projects()
{
    var PrjTb1 = "<input type=text id=PrjNme size=100/>"
    var PrjTb2 = "<textarea rows=5 col=200 wrap=hard></textarea>"
    var Info = "1. Project or activity name:<br>" + PrjTb1 + "<br><br>2. Project or activity description:<br>" + PrjTb2 
    if (document.getElementById('PrjNo').value == 1)
    {
     document.getElementById('AllPrj').innerHTML = "<b>Project or activity 1.</b><br><br>" + Info
    }
}

This function executes well, after an onclick event; however, certain portions of the HTML within the declared variables are not working. For example, within the variable PrjTb2, my textarea's rows and columns do not change. Also, I cannot add the HTML tags <dd> and </dd> anywhere within the variables to create an indentation. What is interesting is that both the textarea properties and the HTML tags, <dd> and </dd>, work within the body of my form, just not in my JS function. Would anyone know what I am doing wrong.

Thank you,

DFM

A: 

It could be that your browser is caching your javascript. Try clearing your cache.

Zack
A: 

Not sure if its the problem, but I'd enclose all your parameters in quotes.

<input type=text id=PrjNme size=100/>

should really be:

<input type='text' id='PrjNme' size='100' />

additionally, depending on your doctype, you may want to change

<br>

to

<br />

Things that are allowed in direct HTML are not necessarily allowed using innerHTML. For example, in Firefox, try embedding a form within a form in js vs html, or in IE, try putting a block element inside an inline element. They both work fine if you have it in HTML, but if you try it with innerHTML, both browsers will complain.

jvenema
Oh well, you beat me to it!
Gab Royer
A: 

I don't know if your syntax error are due to copying you code here, but here is a couple if things I noticed in your code.

  • Are you omitting semi-columns at the end of you lines on purpose?
  • HTML proprieties should be surrounded by quotation marks. (Although not necessary)

Also regarding the <dd></dd>, did you put those inside a definition list (dl)? Because they shouldn't be used as standalone tags.

Gab Royer
Attribute values don't need to be quoted. http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
David Dorward
Indeed, but it is recommended to do so
Gab Royer