473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Obtain Dynamically Created TextBox Name

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
3 4244
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: utterberg | last post by:
Can anyone help me with this problem? I dynamically creates several textboxes using a placeholder. This works fine. But is there a way for me to loop through theese textboxes and retrive its value...
5
by: Jack Johnston | last post by:
Hi there, I am dynamically created a table at runtime on an aspx form. The last cell of each row contains a TextBox in which the user will enter numeric values into. Each textbox I create is...
2
by: JaM | last post by:
Hi all, I have created a gridview vith dynamic textbox columns (they are in variable number, it depends on what things I select from database) aspx code:...
0
by: Silver Oak | last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was created dynamically using iTemplate. I would like to have multi-row editing capability on the DataGrid. I'm trying to...
2
by: HHAAPPYY | last post by:
Hi I am trying to pass value of the textbox along with another value to the query string. when i am retriving the txtbox value it always shows me null, my senario is like this On my...
3
by: raghulvarma | last post by:
I have created only one object for the textbox and that particular textbox is being repeated as many times I want.But if I want to add the values in the database from each and every textbox which...
3
by: foss | last post by:
I have got a Html form with a table. The table contains textfield and a button. When I click the button I want another textfiled to be created. (I have done till here) The problem is that I...
4
by: pooja8389 | last post by:
Good evening.. how can i save the value of dynamically created textbox in data base using System; using System.Data; using System.Configuration; using System.Collections; using...
12
by: pooja8389 | last post by:
good evening... how can store the text value of dynamically created textbox in database. using System; using System.Data; using System.Configuration; using System.Collections; ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.