Click to See Complete Forum and Search --> : change textbox's value directly


BananaQuaalude
12-07-2003, 05:37 PM
Why can I not directly change a textbox's value in code, if I know the name of it? The following throws a "document.frmData.txtOverFlow" is not an object error


if (monthTotal2 > dMonth) {
//this is where I put together the name of the textbox
var txtOverFlow = "Ovr-" + RowData + "-" + matches2
//this line throws the error
document.frmData.txtOverFlow.value = monthTotal2 - dMonth
}

In this case, the name of the textbox is "Ovr-100-12", which is what is assigned to txtOverFlow.

I know I could loop through every element in the form and find the element that matches by name, but that takes too long.

thanks!

fredmv
12-07-2003, 05:45 PM
Do you possibly have a link to an example page so we can see this in action?

BananaQuaalude
12-07-2003, 05:48 PM
No, it's on an Intranet. Is there another part of the code you want to see? The HTML form or anything else?

fredmv
12-07-2003, 05:51 PM
Yes — the code for the HTML form would be quite helpful.

BananaQuaalude
12-07-2003, 06:02 PM
This isn't everything (it's a very large form), but here are the affected elements:


<form name="frmData">
<td>
<center><input type="text" id="<%=RowData & "-" & RS("MonthID")%>" name="Upd-<%=RowData & "-" & RS("EmpProjAssignId") & "-" & intFirstMonth%>" value="<%=intMonth%>" size="1" onBlur="noBlank(this)" onChange="ListTextChanges(this, <%=RowData%>,<%=RS("EmployeeId")%>)">
<input type="text" id="Ovr-<%=RowData & "-" & intFirstMonth%>" name="Ovr-<%=RowData & "-" & intFirstMonth%>" value="" size="1"><%
</form>

If the value of the first textbox exceeds a certain amount, I want to populate the overflow into the second textbox.

fredmv
12-07-2003, 06:13 PM
I believe I see your error. You can't just say:document.frmData.txtOverFlowIt's not going to map that to the value of that variable, it's going to literally look for a form element named txtOverFlow, which as a result throws that error (it must have been an "object expected" error or something similar). You'd have to do something like this to get the functionality you want:document.frmData[txtOverFlow]

BananaQuaalude
12-07-2003, 06:22 PM
Rockin'! That works.

Thank you very much- I can use this in a lot of places.

fredmv
12-07-2003, 06:24 PM
You're very welcome. :D