473,396 Members | 1,712 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,396 software developers and data experts.

how to tell what form to use in javascript

I have a javascript that I am setting a value of a textbox in and have the
following
document.forms[0].textbox1.value = total;
I get a run time error null value but I think the problem is the form index
0. The web application has about 20 forms, is there anyway to tell what the
index should be?
thanks.
--
Paul G
Software engineer.
Oct 22 '08 #1
7 1626
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
>I have a javascript that I am setting a value of a textbox in and have the
following
document.forms[0].textbox1.value = total;
I get a run time error null value but I think the problem is the form
index
0. The web application has about 20 forms, is there anyway to tell what
the
index should be?
Can't you refer to the form by its name...?
http://www.devguru.com/Technologies/...doc_forms.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '08 #2
Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
one form. Also, if the textbox was created by an ASP.NET TextBox server
control (I'm assuming it was since this is an ASP.NET newsgroup), then not
only will the id attribute in the generated HTML be different than the one
in your *.aspx source file, but I would recommend using
document.getElementById(...).value instead (this is what is normally used,
and it does not require an index). My suggestions are based on the
assumption this is an ASP.NET *.aspx Page, if this assumption is incorrect
we may need to see your source code to determine your problem. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:OZ**************@TK2MSFTNGP04.phx.gbl...
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
>>I have a javascript that I am setting a value of a textbox in and have the
following
document.forms[0].textbox1.value = total;
I get a run time error null value but I think the problem is the form
index
0. The web application has about 20 forms, is there anyway to tell what
the
index should be?

Can't you refer to the form by its name...?
http://www.devguru.com/Technologies/...doc_forms.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '08 #3
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Oh****************@TK2MSFTNGP06.phx.gbl...
>>I have a javascript that I am setting a value of a textbox in and have
the
following document.forms[0].textbox1.value = total;
I get a run time error null value but I think the problem is the form
index 0. The web application has about 20 forms, is there anyway to
tell what the index should be?

Can't you refer to the form by its name...?
http://www.devguru.com/Technologies/...doc_forms.html

Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
one form.
ASP.NET pages can contain as many forms as you like, so long as:

1) only one of them has the runat="server" tag

2) they aren't nested
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '08 #4
thanks for the responses, below is the code, it is aspx pages. I created a
small sample web app with only 3 webpages and it works fine but when
integrating it into a large web app I ran into the following problems. When
I call the javascript function (calcBalancenew) and try to pass in the
textbox values there is a java error txbx1 not defined. Note the first
attribute works since I am just passing in integers but the others fail. The
second problem is that in the java script function (calcBalancenew) where I
try to write the results to textbox 4 with

document.forms[0].txbx4.value = total;
I get the error document.forms.0.txbx4 is null or not an object,
so it looks like it can not find it, so thinking I am not accessing the form
correctly.

The large web app uses a master page and all other pages are content of the
master page when it gets loaded in.
I have a simple java function that just adds values in text boxes 1 through
4 and displays the results in text box 4.
In the code behind to use the onblur event with asp.net textbox controls for
4 textboxes I have

txbx1.Attributes["onblur"] = "calcBalancenew(7,1,2,3)";
txbx2.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txtbx2.value,txbx3.val ue,txbx4.value)";
txbx3.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txbx2.value,txbx3.valu e,txbx4.value)";
txbx4.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txbx2.value,txbx3.valu e,txbx4.value)";
--
Paul G
Software engineer.
"Nathan Sokalski" wrote:
Is this an page created by ASP.NET (*.aspx)? If it is, it should only have
one form. Also, if the textbox was created by an ASP.NET TextBox server
control (I'm assuming it was since this is an ASP.NET newsgroup), then not
only will the id attribute in the generated HTML be different than the one
in your *.aspx source file, but I would recommend using
document.getElementById(...).value instead (this is what is normally used,
and it does not require an index). My suggestions are based on the
assumption this is an ASP.NET *.aspx Page, if this assumption is incorrect
we may need to see your source code to determine your problem. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:OZ**************@TK2MSFTNGP04.phx.gbl...
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
>I have a javascript that I am setting a value of a textbox in and have the
following
document.forms[0].textbox1.value = total;
I get a run time error null value but I think the problem is the form
index
0. The web application has about 20 forms, is there anyway to tell what
the
index should be?
Can't you refer to the form by its name...?
http://www.devguru.com/Technologies/...doc_forms.html
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Oct 23 '08 #5
I was able to set the textbox value by using the getElementById as suggested,
still have the other issue though where it does not recognize the arguments
being passed into the onblur event. This is in the C# code behind to create
the onblur events for the web controls.

txbx2.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txtbx2.value,txbx3.val ue,txbx4.value)";
Oct 23 '08 #6
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:A5**********************************@microsof t.com...
I was able to set the textbox value by using the getElementById as
suggested,
still have the other issue though where it does not recognize the
arguments
being passed into the onblur event. This is in the C# code behind to
create
the onblur events for the web controls.

txbx2.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txtbx2.value,txbx3.val ue,txbx4.value)";
.
document.getElementById ('<%=txbx4.ClientID%>').value=total;
How about something like:

"calcBalancenew(" +
txbx1.ClientID + ".value," +
txbx2.ClientID + ".value," +
txbx3.ClientID + ".value," +
txbx4.ClientID + ".value)";

The syntax may not be 100% accurate, but you get the idea...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '08 #7
ok thanks it worked! It was using the actual text for the client id instead
of retrieving the client id when the page was rendered.
--
Paul G
Software engineer.
"Mark Rae [MVP]" wrote:
"Paul" <Pa**@discussions.microsoft.comwrote in message
news:A5**********************************@microsof t.com...
I was able to set the textbox value by using the getElementById as
suggested,
still have the other issue though where it does not recognize the
arguments
being passed into the onblur event. This is in the C# code behind to
create
the onblur events for the web controls.

txbx2.Attributes["onblur"] =
"calcBalancenew(txbx1.value,txtbx2.value,txbx3.val ue,txbx4.value)";
.
document.getElementById ('<%=txbx4.ClientID%>').value=total;

How about something like:

"calcBalancenew(" +
txbx1.ClientID + ".value," +
txbx2.ClientID + ".value," +
txbx3.ClientID + ".value," +
txbx4.ClientID + ".value)";

The syntax may not be 100% accurate, but you get the idea...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '08 #8

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

Similar topics

6
by: What-a-Tool | last post by:
I'm going out out of my mind trying to get this to work with no luck. The error message I get is at the bottom. Can someone please tell me what I'm doing wrong here. I've tried this a million...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
17
by: Mike A | last post by:
Hi, I'm hoping someone can help me with this. I have a URL for which I'd like to limit access to by time. For example,say I have a URL that I don't want accessable on Monday mornings between...
15
by: tabonni | last post by:
I want to check each button groups and save the checked value into a 2 dimensional array. But, it doesn't work. Could anyone tell me what's wrong with my code. My code is as follow: <html>...
5
by: greenflame | last post by:
How can I tell if a variable. I want ot tell whether two variables are: 1. Both numbers. Just a number. same as the number object in javascript. 2. Either one is a string containing a number....
4
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
12
by: Jorge | last post by:
<html><head></head><body><script> (function () { var watch = "Hola !"; (function f () { alert(watch) })(); alert(typeof f); })(); </script></body></html>
5
by: lawrencef | last post by:
I’m new to JavaScript and am trying to creating a dynamic web form in a number of layers. From what I've read, to submit the entire form I need to have all the fields (that are in all the different...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.