PDA

Click to See Complete Forum and Search --> : JS and names in HTML


hpl
Aug 27th, 2002, 09:01 AM
How do I refer to a text field created like this?

<script language="JavaScript"><!--
for (i=1;i<11;i++){
document.write(' <td><input type=text name=t' + i + 'value=100></td>');
}
//--></script>

I have tried to use this
var testing = formName.test.t2.value;
does it not create 10 text fields with the names T1, T2 ... T10? Because that is how I want it to be.

punkpie_uk
Aug 27th, 2002, 09:31 AM
Try this...


<script language="JavaScript"><!--
for (i=1;i<11;i++){
document.write(' <td><input type="text" name="t'+i +'" value="100"></td>');
}
//--></script>

JoshT
Aug 27th, 2002, 10:42 AM
Further elaborating:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Untitled</title>
</head>

<body>
<script language="JavaScript"><!--
for (i=1;i<11;i++){
document.write(' <td><input type="text" name="t'+i +'" value="100"></td>');
}
//--></script>
<div onclick="alert(document.getElementsByName('t1').item(0).value);">CLICK HERE</div>
</body>
</html>

hpl
Aug 29th, 2002, 03:55 AM
Hi punkie_uk and JoshT!
I have a problem which I think is easy for one of you two freaks to answer. The post is http://www.vbforums.com/showthread.php?s=&threadid=194722.
I'm looking forward for a reply :)