By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,286 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,286 IT Pros & Developers. It's quick & easy.

Obtain Dynamically Created TextBox Name

P: n/a
I have a web page that displays multiple records for a company. The
input text boxes that display my data are created dynamically. I'm
creating these input boxes dynamically because the number of records
for each company varies. The name of each input box increments by one
for each record (Ex: A1, B1, C1 | A2, B2, C2, etc..)

On my web page the user will enter in a number into the
txtGrossPayroll(some number) input box. I have added an
OnKeyDown="ComputePremium()" and an OnKeyUp="ComputePremium()" inside
my input boxes. When the user begins to type in a number the following
script runs and displays the premium inside the txtPremium(some number)
input box.
<script type="text/javascript" language="JavaScript">
<!--
function ComputePremium() {
document.ScheduleForm.txtPremium1.value =
Math.round((document.ScheduleForm.txtRate1.value *
(document.ScheduleForm.txtGrossPayroll1.value / 100)), 0);
}
// -->
</script>

Currently, I have the script so that it will only run for my 1st row of
records. Can the script be modified so that it is intelligent enough
to know the correct input box name to use? If so how?

I'm not very familiar with JavaScripts; sorry if this is something that
is very easy to do.

Thanks!
CR Junk

Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
cr****@earthlink.net wrote:
... . The input text boxes that display my data are created
dynamically.
Client-side or server-side?
I'm creating these input boxes dynamically because the number
of records for each company varies. The name of each input
box increments by one for each record (Ex: A1, B1, C1 | A2,
B2, C2, etc..)

On my web page the user will enter in a number into the
txtGrossPayroll(some number) input box. I have added an
OnKeyDown="ComputePremium()" and an OnKeyUp="ComputePremium()"
Two calculations per key press?
inside
my input boxes. When the user begins to type in a number the
following script runs and displays the premium inside the
txtPremium(some number) input box.
<script type="text/javascript" language="JavaScript">
<!--
This "hide scripts form older browsers" stuff is superfluous.
function ComputePremium() {
document.ScheduleForm.txtPremium1.value =
Math.round((document.ScheduleForm.txtRate1.value *
(document.ScheduleForm.txtGrossPayroll1.value / 100)), 0); ^
What is the zero for?
}
// -->
</script>

Currently, I have the script so that it will only run for
my 1st row of records.
Because you have hard-coded the form control name.
Can the script be modified so that it is intelligent
enough to know the correct input box name to use?
Yes.
If so how?
By providing the row information as a parameter to the function call, in
some form, and then using bracket notation to reference the form
controls in the correct row.
I'm not very familiar with JavaScripts; sorry if this
is something that is very easy to do.


It is very easy to do, but how it is specifically done depends on the
HTML being scripted.

Richard.
Jul 23 '05 #2

P: n/a
Richard Cornford wrote:
Client-side or server-side?
The input boxes are being created on the server-side.
Two calculations per key press?
I didn't think that that I needed to have OnKeyUp and OnKeyDown, but a
script that I used as a reference used both events. I went with how
they had created their script. Will either one of these accomplish
what I want?
What is the zero for?
Sorry about that. This is old code that I forgot to remove from the
desktop app that I'm converting and moving online.
By providing the row information as a parameter to the function call, in

some form, and then using bracket notation to reference the form
controls in the correct row.

Since I'm creating each input box on the server-side, I now see how I
can pass the row number to the function when the server is generating
the HTML. Can you provide an example of what the syntax looks like for
using bracket notation when referencing the form controls in the
formula?
Thanks for your help Richard!

CR Junk

Jul 23 '05 #3

P: n/a
Hi Richard,

I continued playing around with my function and came up with the
following:

function ComputePremium(i) {
document.ScheduleForm["txtPremium" + i].value =
Math.round((document.ScheduleForm["txtRate" + i].value *
(document.ScheduleForm["txtGrossPayroll" + i].value / 100)));
}

So far, it seems to be working correctly. Is this what you were
refering to when you mentioned bracket notation.

Thanks,

CR Junk

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.