/    Sign up×
Community /Pin to ProfileBookmark

change textbox’s value directly

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!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@fredmvDec 07.2003 — Do you possibly have a link to an example page so we can see this in action?
Copy linkTweet thisAlerts:
@BananaQuaaludeauthorDec 07.2003 — No, it's on an Intranet. Is there another part of the code you want to see? The HTML form or anything else?
Copy linkTweet thisAlerts:
@fredmvDec 07.2003 — Yes — the code for the HTML form would be quite helpful.
Copy linkTweet thisAlerts:
@BananaQuaaludeauthorDec 08.2003 — 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.
Copy linkTweet thisAlerts:
@fredmvDec 08.2003 — 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 [i]txtOverFlow[/i], 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]
Copy linkTweet thisAlerts:
@BananaQuaaludeauthorDec 08.2003 — Rockin'! That works.

Thank you very much- I can use this in a lot of places.
Copy linkTweet thisAlerts:
@fredmvDec 08.2003 — You're very welcome. ?
×

Success!

Help @BananaQuaalude spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...