Solved

insert   between inputs

Posted on 2004-09-02
4
288 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now