www.webdeveloper.com
Results 1 to 5 of 5

Thread: Adding a line break

  1. #1
    Join Date
    Apr 2011
    Posts
    6

    Adding a line break

    Hi,

    I'm very new to JS and just playing around with some basic stuff, so far I have;

    PHP Code:
    var currentTxtBx 0;

    function 
    addTxtBx(){
        
    if (
    currentTxtBx<10){
        
        if (
    currentTxtBx<10){

            var 
    txtBxTable document.getElementById('txtBoxTable');
              var 
    newTxtBx document.createElement('input'); // creates the text box element
              
    newTxtBx.type 'text'// declares the text box as text
            
    newTxtBx.name 'check'+(currentTxtBx+1); // declares the value of the text box
              
    currentTxtBx++;
              
    txtBoxTable.appendChild(newTxtBx);
        }
    }
    else
    {
        
    alert('cannot add more than 10 boxes');
    }

    This just creates up to 10 text boxes when the user presses the button. However, the text boxes are placed side by side until they have to go on to a new line.

    How would I go about creating and inserting a line break so that after each text box a line break would occur so that they're all place one below another?

    Thanks

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    I'm totally guessing, here:

    txtBoxTable.appendChild(newTxtBx+'<br />');
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

  3. #3
    Join Date
    Apr 2011
    Posts
    6
    nah that didn't work

  4. #4
    Join Date
    Mar 2011
    Posts
    14
    I'm no wiz myself, but you could try creating a new variable with a line break?

    var myLineBreak = "<br />";

    and then just call it where necessary?

    Gomhon

  5. #5
    Join Date
    Aug 2007
    Posts
    3,767
    Well you could style them, or add a line break.
    Code:
    txtBoxTable.appendChild(document.createElement("br"));
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles