Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript form help - dynamic field names...PLZ

Status
Not open for further replies.

shu745

Programmer
May 14, 2001
79
US
Hey all, I was hoping someone could help me. I am having some problems getting javascript to evaluate some select list field names with have been created dynamically. Here is the page:

here is the script:
----------------------------------------
<html>
<head>
<SCRIPT language="javascript">
<!--
function writeList(position,id) {
position='pos'+position; // seems like field names must begin with character
var eleName = position+id; // create select list element names

document.write('<select name="'+eleName+'" style="width:70;" onChange="alert(\'name:\'+this.name);checkList(this,'+id+');" class="fieldsml">');
document.write('<option value="-1">--');
document.write('<option value="Final Value">Final Value');
document.write('<option value="Hedonic">Hedonic');
document.write('<option value="TAV">TAV');
document.write('<option value="RSI">RSI');
document.write('<option value="Emulation">Emulation');
document.write('<option value="CASA">CASA');
document.write('<option value="PASS">PASS');
document.write('<option value="HPA">HPA');
document.write('<option value="HVE">HVE</option>');
document.write('</select>');
}

function checkList(e,id) {
var x = document.forms.countyForm;
var repNum = 9; //number of Reports
var arrTmpVal = new Array();
var val = e.value;
var pos = '';
var eleName ='';

for(i=0;i<repNum;i++){ // loop to recreate all select list element names in corresponding row
pos = 'pos'+(i+1);
eleName = pos+id;
alert(eleName); // matches all element names in row
alert(x.eleName); // does not recognize, why not????
}
}
//-->
</SCRIPT>
</head>
<body leftmargin="0" rightmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br><br>
<table width="750" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>Autauga</td>
<td>&nbsp;</td>
<td><script>writeList(1,'1001')</script></td>
<td>&nbsp;</td>
<td><script>writeList(2,'1002')</script></td>
<td>&nbsp;</td>
<td><script>writeList(3,'1003')</script></td>
<td>&nbsp;</td>
<td><script>writeList(4,'1004')</script></td>
<td>&nbsp;</td>
<td><script>writeList(5,'1005')</script></td>
<td>&nbsp;</td>
<td><script>writeList(6,'1006')</script></td>
<td>&nbsp;</td>
<td><script>writeList(7,'1007')</script></td>
<td>&nbsp;</td>
<td><script>writeList(8,'1008')</script></td>
<td>&nbsp;</td>
<td><script>writeList(9,'1009')</script></td>
</tr>
<tr>
<td>Baldwin</td>
<td>&nbsp;</td>
<td><script>writeList(1,'2001')</script></td>
<td>&nbsp;</td>
<td><script>writeList(2,'2002')</script></td>
<td>&nbsp;</td>
<td><script>writeList(3,'2003')</script></td>
<td>&nbsp;</td>
<td><script>writeList(4,'2004')</script></td>
<td>&nbsp;</td>
<td><script>writeList(5,'2005')</script></td>
<td>&nbsp;</td>
<td><script>writeList(6,'2006')</script></td>
<td>&nbsp;</td>
<td><script>writeList(7,'2007')</script></td>
<td>&nbsp;</td>
<td><script>writeList(8,'2008')</script></td>
<td>&nbsp;</td>
<td><script>writeList(9,'2009')</script></td>
</tr>
<!-- control row : controls table's widths-->
<tr>
<td width="75" class="control"><img src="../images/spacer.gif" width="75" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
<td width="5" class="control"><img src="../images/spacer.gif" width="5" height="1" /></td>
<td width="70" class="control"><img src="../images/spacer.gif" width="70" height="1" /></td>
</tr>
</table>
</body>
</html>
----------------------------------------

Any help is appreciated. Thx in advance!
- Shu
 
I think i got it! I just changed the second parameter of the writeList() fx to be the same for each row that way I can associate each rows select lists to by it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top