...

View Full Version : HTML within JAVA SCRIPT



yarik
06-11-2003, 04:11 AM
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

}

JustAsking
06-11-2003, 04:38 AM
Not too sure, give this a go.



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

}

duniyadnd
06-11-2003, 02:39 PM
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:



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum