option & textnode

A

Andrew Koptyaev

I have next piece of code.
I have a question - why text "Months" not in there option line of form.
Just after form. I is not right for me. I want in there option line.

var oOptionIntervalInputM = cElement('option');
cAttribute(oOptionIntervalInputM,'value','m');
var oOptionIntervalInputTextM = document.createTextNode('Months');
oOptionIntervalInputM.appendChild(oOptionIntervalInputTextM);

function cElement(el) {
this.obj = document.createElement(el);
return this.obj;
}

function cAttribute(obj,att,val) {
obj.setAttribute(att,val);
return this.obj;
}
 
A

Andrew Koptyaev

Why your code didn't work as intended is not obvious from what you
posted. As roundabout as it is, it would probably "work" (in an unsafe
way). The error you describe might be caused when you try to add the new
option to a select element.

Try the "new Option" suggestion (first code snippet), and be careful
about how you use "this".

Thank you. I just was wrong in add new option to select. I should use
appendChild.
 

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,079
Messages
2,570,574
Members
47,205
Latest member
ElwoodDurh

Latest Threads

Top