Add Element to Form

M

MC

Hi,

I am looking to programmatically add an element to a form, in this case a
SPAN message.

<span class="Arial090NN" style="COLOR: red;LEFT: 85px; TOP: 176px; HEIGHT:
9px; TEXT-ALIGN: left; Z-INDEX: 100; POSITION: absolute;">My Message</span>

I've been looking on the web and I've not been able to find this. Any ideas?

Thanks,
Mica
 
J

Joost Diepenmaat

MC said:
Hi,

I am looking to programmatically add an element to a form, in this case a
SPAN message.

<span class="Arial090NN" style="COLOR: red;LEFT: 85px; TOP: 176px; HEIGHT:
9px; TEXT-ALIGN: left; Z-INDEX: 100; POSITION: absolute;">My Message</span>

I've been looking on the web and I've not been able to find this. Any ideas?

see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html

You probably want something like this:

var form = document.getElementById("id-of-form");
// or
var form = document.forms["name-of-form"];

var span = document.createElement("span");
span.className="Arial090NN"; // if this is what I think it is it's a really
// stupid class name - class names should be
// "semantic", not indicative of any particular style


span.style.color="red";
span.style.left="85px";
// etc
// usually you're better off putting styles in the appropriate class and/or id
// in a seperate stylesheet anyway


span.appendChild(document.createTextNode("My Message");

form.appendChild(span);
 
M

MC

Joost,

You be the man! So many times I have needed this.

I agree on your comments but in this case it fits. This is a very complex
6-page form with many types of fonts that are standard accross a whole
library of forms.

Thank you AGAIN!
Mica

Joost Diepenmaat said:
MC said:
Hi,

I am looking to programmatically add an element to a form, in this case a
SPAN message.

<span class="Arial090NN" style="COLOR: red;LEFT: 85px; TOP: 176px;
HEIGHT:
9px; TEXT-ALIGN: left; Z-INDEX: 100; POSITION: absolute;">My
Message</span>

I've been looking on the web and I've not been able to find this. Any
ideas?

see http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html

You probably want something like this:

var form = document.getElementById("id-of-form");
// or
var form = document.forms["name-of-form"];

var span = document.createElement("span");
span.className="Arial090NN"; // if this is what I think it is it's a
really
// stupid class name - class names should be
// "semantic", not indicative of any
particular style


span.style.color="red";
span.style.left="85px";
// etc
// usually you're better off putting styles in the appropriate class
and/or id
// in a seperate stylesheet anyway


span.appendChild(document.createTextNode("My Message");

form.appendChild(span);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top