1. #1

    Registered
    21/04/09
    Location
    zwevegem
    Posts
    367
    iTrader
    7 (89%)
    Mentioned
    0 Post(s)
    Reputation
    0/2

    <br /> toevoegen door js

    Dit is mijn huidig script
    Code:
               
    <input id="button" type="button" value="add input" /><br /><br />
    <div id="inputs"></div> 
    <script type="text/javascript">
    var target = document.getElementById("inputs"), count = 1, count2 = 1, addInput = function() {
    	
    	
        var input = document.createElement("input");
        input.setAttribute("name", "artikel"+count);
        input.setAttribute("id", "artikel"+count);
        input.setAttribute("value", "artikel"+count);
        input.setAttribute("size", 30);
        input.className = "foo";
        target.appendChild(input);
        count++;
    	
        var input = document.createElement("input");
        input.setAttribute("name", "prijs"+count2);
        input.setAttribute("id", "prijs"+count2);
        input.setAttribute("value", "prijs"+count2);
        input.setAttribute("size", 30);
        input.className = "foo";
        target.appendChild(input);
        count2++;
     
    };
    document.getElementById("button").onclick = addInput;
    </script>
    als ik op de knop add input klik, krijg ik dus 2 extra inputvelden met hun unieke waarden.
    maar ik had graag een <br /> erna gekregen.

    ik ben een totale leek op vlak van javascript, ik heb nu al tijdje zitten googlen maar niets gevonden dat werkt.

    document.createElement('br'); heb ik al overal proberen te plaatsen, maar niets dat het doet lukken.


    thx,
    Lorenzo
    no votes  

  2. #2
    KenSpectre's Avatar
    Registered
    06/12/06
    Location
    Tongeren
    Posts
    1,880
    iTrader
    26 (100%)
    Mentioned
    0 Post(s)
    Je kan html toevoegen door:

    Code:
       document.write('<p>This is a paragraph</p>');
    dus voor jou:

    Code:
       document.write('<br />');
    PSN:SpectreX15

    What doesn't kill me makes me stronger. What does kill me, I'll deal with when I respawn.
    I am root. If you see me laughing, you better have a backup!
    no votes  

  3. #3

    Registered
    21/04/09
    Location
    zwevegem
    Posts
    367
    iTrader
    7 (89%)
    Mentioned
    0 Post(s)
    Reputation
    0/2
    die had ik ook al ergens gevonden,

    maar als ik dat in mijn functie laat uitvoeren krijg ik een blanco pagina als ik op add input klik.

    En als ik het voor of na
    document.getElementById("button").onclick = addInput;
    plaats, doet het ook niets.

    tog bedankt voor uw hulp
    no votes  

  4. #4
    passero's Avatar
    Registered
    28/11/03
    Location
    Drongen
    Posts
    6,665
    iTrader
    5 (100%)
    Mentioned
    0 Post(s)
    Reputation
    6/28
    Voor (of erna gezien ge begint met er eentje toe te voegen)

    target.appendChild(input);

    doet ge

    target.innerHTML += "<br/>";
    no votes  

  5. #5

    Registered
    21/04/09
    Location
    zwevegem
    Posts
    367
    iTrader
    7 (89%)
    Mentioned
    0 Post(s)
    Reputation
    0/2
    Quote Originally Posted by passero View Post
    This quote is hidden because you are ignoring this member. Show
    Voor (of erna gezien ge begint met er eentje toe te voegen)

    target.appendChild(input);

    doet ge

    target.innerHTML += "<br/>";
    thank you, thank you, thank you ! ! +rep
    no votes  

  6. #6
    adrianhates's Avatar
    Registered
    23/01/06
    Posts
    2,115
    iTrader
    0
    Mentioned
    0 Post(s)
    Reputation
    23/23
    Beter zou zijn om aan uwe laatste input een margin te geven.

    input.style.marginBottom = "10px";

    of met jQuery

    $("input#id").css("margin-bottom","10px");
    no votes  

  7. #7
    passero's Avatar
    Registered
    28/11/03
    Location
    Drongen
    Posts
    6,665
    iTrader
    5 (100%)
    Mentioned
    0 Post(s)
    Reputation
    6/28
    input fields worden toch standaard als inline beschouwd dus de margin-bottom zal toch niets uitmaken?

    je moet dan ook de display = "block" zetten of niet?
    dan kan je dat idd doen zonder br.
    no votes  

  8. #8
    adrianhates's Avatar
    Registered
    23/01/06
    Posts
    2,115
    iTrader
    0
    Mentioned
    0 Post(s)
    Reputation
    23/23
    Quote Originally Posted by passero View Post
    This quote is hidden because you are ignoring this member. Show
    input fields worden toch standaard als inline beschouwd dus de margin-bottom zal toch niets uitmaken?

    je moet dan ook de display = "block" zetten of niet?
    dan kan je dat idd doen zonder br.
    Goe opgemerkt!
    Verbetering:
    Beter zou zijn om aan uwe laatste input een margin te geven.

    input.style.display = "block";
    input.style.marginBottom = "10px";

    of met jQuery

    $("input#id").css("display","block");
    $("input#id").css("margin-bottom","10px");

    is uiteindelijk meer code dan innerHTML , maar volgens mij is da een beetje deprecated
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in