Solved

insert   between inputs

Posted on 2004-09-02
4
289 Views
Last Modified: 2012-06-21
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
Comment
Question by:mmc98dl1
4 Comments
 
LVL 3

Expert Comment

by:Ayesha_K
ID: 11961375
have you tried inserting space as it is like;

var b = '';
b = ' ';
0
 
LVL 12

Author Comment

by:mmc98dl1
ID: 11961391
yes, I still get the same type mismatch error.
0
 
LVL 6

Expert Comment

by:sathishv
ID: 11961727
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
 
LVL 19

Accepted Solution

by:
dakyd earned 50 total points
ID: 11967079
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now