[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

insert   between inputs

Posted on 2004-09-02
4
Medium Priority
?
299 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
[X]
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
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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

656 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