473,324 Members | 2,239 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,324 software developers and data experts.

how to get/set textbox values client side document.getElementByID

Hello,

I'm trying to set up an ASP.NET 2.0 form where the user enters values in
WebControls.TextBoxes for amount owing, interest and late fees and a
JavaScript function totals the three values and sets the value of a label
(lblTotal) to the sum of the three textbox values. The form is in a content
place holder.
I've added the following block of code in my form load.
The idea is to pass the three parameters to the update function:

txtAmount.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
txtInterest.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
txtLateFees.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
function update(amt, itr, ltf)
{
var total = 0.00;
if(amt)
total += parseFloat(amt) ;
if(itr)
total += parseFloat(itr) ;
if(ltf)
total += parseFloat(ltf);
document.getElementById('ctl00$ContentPlaceHolder1 $lblTotal').value =
total.toFixed(2);
}
</script>
The code appears to be failing with "object required" at this point. When
I debug in VS 2005 I get an "object required" error at the following code
block. It doesn't appear to recognize txtAmount.ClientID as a valid pointer
to the control.

<td style="width: 2px">
<input
name="ctl00$ContentPlaceHolder1$txtAmount" type="text"
id="ctl00_ContentPlaceHolder1_txtAmount"
onchange="update(document.getElementById('txtAmoun t.ClientID').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);"
style="height:14px;width:100px;" /></td>

I'm a bit of a Javascript newbie and would sincerely appreciate any help I
could get here.

Thanks in advance,

Andre Ranieri
Aug 21 '06 #1
1 36484
ClientID is a serverside property, javascript knows nothing about it. you
have to build client script with the actual value of ClientID

string script ="var id = document.getElementById('" + myControl.ClientId +
"');";

-- bruce (sqlwork.com)


"Andre Ranieri" <An**********@discussions.microsoft.comwrote in message
news:A1**********************************@microsof t.com...
Hello,

I'm trying to set up an ASP.NET 2.0 form where the user enters values in
WebControls.TextBoxes for amount owing, interest and late fees and a
JavaScript function totals the three values and sets the value of a label
(lblTotal) to the sum of the three textbox values. The form is in a
content
place holder.
I've added the following block of code in my form load.
The idea is to pass the three parameters to the update function:

txtAmount.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
txtInterest.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
txtLateFees.Attributes.Add("onchange",
"update(document.getElementById('txtAmount.ClientI D').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);");
function update(amt, itr, ltf)
{
var total = 0.00;
if(amt)
total += parseFloat(amt) ;
if(itr)
total += parseFloat(itr) ;
if(ltf)
total += parseFloat(ltf);
document.getElementById('ctl00$ContentPlaceHolder1 $lblTotal').value =
total.toFixed(2);
}
</script>
The code appears to be failing with "object required" at this point.
When
I debug in VS 2005 I get an "object required" error at the following code
block. It doesn't appear to recognize txtAmount.ClientID as a valid
pointer
to the control.

<td style="width: 2px">
<input
name="ctl00$ContentPlaceHolder1$txtAmount" type="text"
id="ctl00_ContentPlaceHolder1_txtAmount"
onchange="update(document.getElementById('txtAmoun t.ClientID').value,
document.getElementById('txtLateFees.ClientID').va lue,
document.getElementById('txtInterest.ClientID').va lue);"
style="height:14px;width:100px;" /></td>

I'm a bit of a Javascript newbie and would sincerely appreciate any help I
could get here.

Thanks in advance,

Andre Ranieri

Aug 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jason | last post by:
I've got this javascript routine (i found on google - thank you) in an asp.net page that on page reload sets the cursor of a textbox to the last line. It works great! Using a similar concept, I...
1
by: Hardy Wang | last post by:
Guys, I have a web form with some <Asp:TextBox> controls, on some condition, I need to trigger a client side JavaScript to clean all values of these boxes, like below: function DisableForm() {...
8
by: Sergei | last post by:
Hi, I am displaying modal dialog and passing values from the main form to the modal dialog and back. It works fine but if I used the following syntax on Page_Load(just for testing) in VB to...
7
by: Sandy | last post by:
Hello - I have a form that when submitted checks the database and if the username is already taken, a label shows indicating same. I need to make that label NOT visible after the user clicks...
1
by: VB Programmer | last post by:
With HTML, how do I get the value of a textbox in an ItemTemplate column within a datagrid? Simple shopping cart. For each row: 1 column is a textbox where they can enter the quantity. 1...
2
by: alanliang | last post by:
I want to be able to populate an asp textbox with logitude and lattitude values whenever a user selects a point or creates a marker on google maps. Simply, how do I change an asp's textbox value...
2
by: ibiza | last post by:
Hi all, I have a quite big webform that has about ~15 validators. I found, after having looked at the generated HTML source, that the filesize is pretty big : about 65KB. Then, I added to every...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
6
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, I found out that Text property is perserved, but disable/enable status is not preserved, especially I change this setting of a server side text box with client side javascipt and then post...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: 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.