• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

insert   between inputs

I have the following script and it works fine without         var b = '';  b = ' ';  d.appendChild(b); but I need a space between the 2 inputs the script inserts.

The error I get is Typemismatch on the d.appendChild(b); I am using IE 6 and it only needs to work on IE 6 +.

Can anyone point to where I am going wrong?

Thanks


 function newVendor(){
      
        var d = document.getElementById('additionalVendors');
        var n = document.createElement("input");
        n.setAttribute("type","text");
        n.name="cli_additionalVendorsFirstName_" + (d.childNodes.length+1);
        n.value="";
        n.style.width="110px";
        n.maxlength=50;
        d.appendChild(n);
        
        var b = '';
        b = ' ';
        d.appendChild(b);
        
        var s = document.createElement("input");
        s.setAttribute("type","text");
        s.name="cli_additionalVendorsSurName_" + (d.childNodes.length+1);
        s.value="";
        s.style.width="110px";
        s.maxlength=50;
        d.appendChild(s);
        return true
       }
0
mmc98dl1
Asked:
mmc98dl1
1 Solution
 
Ayesha_KCommented:
have you tried inserting space as it is like;

var b = '';
b = ' ';
0
 
mmc98dl1Author Commented:
yes, I still get the same type mismatch error.
0
 
sathishvCommented:
With appendChild you need to use an element, rather than text. Try if the following method works (with nbsp inside a span element),

var b = document.createElement("span");
b.innerHTML = " ";
d.appendChild(b);

Hope this helps.

Cheers,
Sathish
0
 
dakydCommented:
Another alternative is to use the margins on the inputs rather than inserting more nodes.  I added the two element.style.margin lines, so there should be a total of 10px between the two inputs.  The gap might be more pronounced than you want, but you can always change the value to a different number of pixels.  Hope that helps.

function newVendor(){
       var d = document.getElementById('additionalVendors');
       var n = document.createElement("input");
       n.setAttribute("type","text");
       n.name="cli_additionalVendorsFirstName_" + (d.childNodes.length+1);
       n.value="";
       n.style.width="110px";
       n.maxlength=50;
       n.style.marginRight = "5px";  // can change this if gap is too big/small
       d.appendChild(n);
       
       var b = '';
       b = ' ';
       d.appendChild(b);
       
       var s = document.createElement("input");
       s.setAttribute("type","text");
       s.name="cli_additionalVendorsSurName_" + (d.childNodes.length+1);
       s.value="";
       s.style.width="110px";
       s.maxlength=50;
       s.style.marginLeft = "5px"; // can change this if gap is too big/small
       d.appendChild(s);
       return true
      }
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now