javascript - create textarea with name

Advert test
#1
this could be a long shot but I am stuck with this code atm. I don't know anything about javascript but i have found myself trying to edit it. I want to create a textarea with a name.

I got this sample script that does the job perfectly but it is just missing a name for the textarea. This is just a bit of it:

Code:
function catchIt(e) {
        if (editing) return;
        if (!document.getElementById || !document.createElement) return;
        if (!e) var obj = window.event.srcElement;
        else var obj = e.target;
        while (obj.nodeType != 1) {
                obj = obj.parentNode;
        }
        if (obj.tagName == 'TEXTAREA' || obj.tagName == 'A') return;
        while (obj.nodeName != 'P' && obj.nodeName != 'HTML') {
                obj = obj.parentNode;
        }
        if (obj.nodeName == 'HTML') return;
        var x = obj.innerHTML;
        var y = document.createElement('textarea');
//      y.appendChild(document.createTextNode(x));
        var z = obj.parentNode;
        z.insertBefore(y,obj);
        z.insertBefore(butt,obj);
        z.removeChild(obj);
        y.value = x;
        y.focus();
        editing = true;
        return false;
}
The output of which in HTML is just <textarea></textarea> That's basically it. I need to change the script to create something like <textarea name="text"></textarea>

I have tried adding lines such as this in but I have yet to get any results!...

Code:
      f.appendChild(document.name(text));
I have been searching online all night for a solution so it would be nice to get it wrapped up! Thanks for any help.
 
#2
try this:
Code:
var y = document.createElement('textarea');
y.setAttribute("name","mytextarea");
y.setAttribute("cols","10");
y.setAttribute("rows","2");
 
#5
yeah! as I said, I don't know anything about JavaScript! But it is a language that i really want to and do plan to learn! My attempt was just a wild guess from looking at the rest of the code... Once I get my head over PHP then its JavaScript all the way!
 
Top