Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

insert   between inputs

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JavaScript let vs var 5 34
How to combine and minify CSS and JS files 5 15
Access RV042 GUI / Browser Issues 25 46
Page auto-refreshes when scrolled on iPhone. 5 53
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

789 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