Yes, because the script you used is hard coded to use a specific id as container to render the fields. But I second Steven on that one.
The link he sent you is way more versatile.
Look at those lines, it should do what you want:
Code:
function createField(_type){
var o=document.createElement('input');
switch(_type){
case 'text':
case 'password':
case 'file':
case 'submit':
case 'button':
o.type=_type;
break;
default:
alert('The input type '+_type+' is invalid');
o=null;
}
return o;
}
function addField(_type,_name,_id,_class,_parent){
var trg=document.getElementById(_parent);
if(!trg){
alert('Parent element ID '+_parent+' was not found');
return false;
}
var inp=createField(_type);
inp.name=_name;
inp.id=_id;
inp.className=_class;
trg.appendChild(inp);
return true;
}
All in 30 lines...
To use it, simply call addField() with the parameters you need, and in _parent, give the ID of the container into which that field should be added.
I did not included <select> and <textarea> because they are a bit different from the <input>, but it would be relatively easy to do so.
__________________
Listen to the ducky: "This is awesome!!!"
|