Image

Using Dynamic HTML Var Name to build Dynamic Java/jsp var names

I found the solution and follows under the solution cut!

I have created the following dynamic HTML columns Col1, Col2, ...
I need to access these named variables and assign them to both a javascript and java/jsp variable.
Any ideas on how to do this.


Old Code

<%for (int x=0; x
[Error: Irreparable invalid markup ('<rankcntcolumns.intvalue();>') in entry. Owner must fix manually. Raw contents below.]

<b>I found the solution and follows under the solution cut!</b>

<strike>I have created the following dynamic HTML columns Col1, Col2, ...
I need to access these named variables and assign them to both a javascript and java/jsp variable.
Any ideas on how to do this.</strike>

<lj-cut text="Old Code snippet"><b>Old Code</b>

<%for (int x=0; x<RankCntColumns.intValue(); x++){CurrRank=((RankVo)FixFillInfo.getRankList().get(x)).getRankSeqCode();%>
<input type='hidden'
id='HRankCol<%=CurrRank.intValue()%>'
name=HRankCol<%=CurrRank.intValue()%>
value ="<%=CurrRank.intValue()%>"/
>
<input type='hidden'
id='HRankFillQty<%=CurrRank.intValue()%>'
name=HRankFillQty<%=CurrRank.intValue()%>
value ="<%=CurrRank.intValue()+1%>"/
>
<%}%>

JSP current code not working ....

function fred()
{
var f = document.all.frmFixFill;
for (var x=0; x<f.HiddenRankCntColumns.value; x++)
{
alert(f.'HRankFillQty'+x.value);
}
}

</lj-cut>

<lj-cut text="Solution"><b>The new fred function:<b>
function fred()
{
var f = document.all.frmFixFill;
var fillname = null;
for (var x=1; x<=f.HiddenRankCntColumns.value; x++)
{
fillname = "document.frmFixFill.HRankFillQty" + x + ".value";
alert(eval(fillname));
}
}
</lj-cut>

x-posted to <lj user="javascript"> and other JSP communities