Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTML within JAVA SCRIPT

    Hi everyone!
    i am very new to Java Script and HTML
    could someone tell me please is it the right syntax ?
    The problem that i am having with this script: the location of the dynamic fields that are created.
    it seems to me that something wrong with this line: '<tr><td ALIGN=RIGHT>'+'<input size=10 maxlength=9 value="'+[i]+'" name="Breakpoint"></td></tr><BR>'

    I think that trs and tds are not created because the field is created in the very left of this form

    function addNewField(){

    var sHTML = ""
    //sHTML = '<table>'

    //write previous fields with data from array
    for(i=0; i<totalRows; i++)
    sHTML+='<tr><td ALIGN=RIGHT>'+'<input size=10 maxlength=9 value="'+[i]+'" name="Breakpoint"></td></tr><BR>'
    //add empty (new) field
    sHTML+='<tr><td<td ALIGN=RIGHT>'+'<input value="" size=10 maxlength=9 name="Breakpoint"></td></tr><br>'
    //sHTML +='</table>'


    totalRows = totalRows + 1;

    //displays HTML in the <DIV id="content"></DIV> container
    document.all.content.innerHTML = sHTML

    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    -27° 28' 22" , 153° 1' 22"
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not too sure, give this a go.

    Code:
    function addNewField(){
    
    var sHTML = " "
    
    //write previous fields with data from array
    
    for(i=0; i<totalRows; i++){
    
      sHTML = '<table><tr><td align=right><input size=10 maxlength=9 value='[i]' name=Breakpoint></td></tr>'; 
    
      sHTML = sHTML + '<tr><td<td align=right><input value= size=10 maxlength=9 name=Breakpoint></td></tr></table>';
    
      totalRows = totalRows + 1;
    }
    //displays HTML in the <DIV id="content"></DIV> container
    document.all.content.innerHTML = sHTML
    
    }
    "Computers are considered female - As soon as you make a commitment to one, you find yourself spending half your paycheck on accessories for it."

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Couple of things:

    var totalRows value is undefined. So that could mean that it doesn't go in the for loop at all.

    Secondly, you repeated some of your code, I don't know if one was supposed to be commented out or is it actually like that?

    Other than that, your code could go something like so:

    Code:
    function addNewField(){
    
    var sHTML = "";
    sHTML = "<table>";
    
    //write previous fields with data from array
    
    for(i=0; i<totalRows; i++)
    {
    sHTML+="<tr><td ALIGN=\"RIGHT\"><input size=\"10\" maxlength=\"9\" value=\""+[i]+"\" name=
    \"Breakpoint\"></td></tr>";
    
    //add empty (new) field
    //I don't know why this is repeating though..
    sHTML+="<tr><td ALIGN=\"RIGHT\"><input size=\"10\" maxlength=\"9\" value=\""+[i]+"\" name=
    \"Breakpoint\"></td></tr>";
    }
    
    sHTML +="</table>";
    
    
    totalRows = totalRows + 1; 
    
    //displays HTML in the <DIV id="content"></DIV> container
    document.all.content.innerHTML = sHTML;
    
    }
    I didn't test this code out... but it seems okay otherwise.. I don't know what you doing with the totalRows = totalRows+1 line, at least what you trying to get at.


  •  

    Posting Permissions

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