Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Obtain Dynamically Created TextBox Name

Reply
Thread Tools

Obtain Dynamically Created TextBox Name

 
 
crjunk@earthlink.net
Guest
Posts: n/a
 
      06-24-2005
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

 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      06-25-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
crjunk
Guest
Posts: n/a
 
      06-27-2005
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

 
Reply With Quote
 
crjunk
Guest
Posts: n/a
 
      06-27-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
How to get the TextBox Value in a dynamically created HtmlTable??? Raed Sawalha ASP .Net 2 10-05-2004 06:57 AM
Dynamically created asp textbox - need to assign a different ID Shilpi Chaudhry ASP .Net 1 09-15-2004 06:32 PM
Capturing Data of Dynamically Created TextBox's Jack Johnston ASP .Net 5 07-28-2003 09:57 AM



Advertisments