473,799 Members | 3,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Specifying a form by name? Problems with document.forms[x]

Hello,

I have code similar to:

if (beforeToday(do cument.forms[0].sStartDate.val ue))

that was broken when an include file had a form added to it. Since my
form was no longer the 0th form, my code was broken. Is there any way
to specify a form by name or some other work around for this
situation?

-Eric

Mar 7 '07 #1
6 18746
"Eric" <er**********@g mail.comwrote in message
news:11******** **************@ 8g2000cwh.googl egroups.com...
Hello,

I have code similar to:

if (beforeToday(do cument.forms[0].sStartDate.val ue))

that was broken when an include file had a form added to it. Since my
form was no longer the 0th form, my code was broken. Is there any way
to specify a form by name or some other work around for this
situation?
Sure:

<form name="form1">

if (beforeToday(do cument.form1.sS tartDate.value) )
Mar 7 '07 #2
On Mar 7, 12:16 am, "Eric" <eric.gofo...@g mail.comwrote:
Hello,

I have code similar to:

if (beforeToday(do cument.forms[0].sStartDate.val ue))

Is there any way
to specify a form by name or some other work around for this
situation?
Use:
document.forms["form_name"]

Example:
----------
....
<script ... >
function test(){
alert(document. forms["form1"].sStartDate.val ue)
}

</script>
....
<form name="form1" onsubmit="test( );return false" action="#" ...>
<input name="sStartDat e" type="text">
<input type="submit" value="Test">
....

</form>
....
---------

that means -
document.forms[formIndex] == document.forms[formNameAsStrin g]

Mar 7 '07 #3
On Mar 7, 11:57 am, scripts.cont... @gmail.com wrote:
On Mar 7, 12:16 am, "Eric" <eric.gofo...@g mail.comwrote:
Hello,
I have code similar to:
if (beforeToday(do cument.forms[0].sStartDate.val ue))
Is there any way
to specify a form by name or some other work around for this
situation?

Use:
document.forms["form_name"]

Example:
----------
...
<script ... >
function test(){
alert(document. forms["form1"].sStartDate.val ue)

}

</script>
...
<form name="form1" onsubmit="test( );return false" action="#" ...>
<input name="sStartDat e" type="text">
<input type="submit" value="Test">
...

</form>
...
---------

that means -
document.forms[formIndex] == document.forms[formNameAsStrin g]
you can use document.getEle mentById('id') to get any element.
Element used by this method won't uses forms so no problem in
accessing the elements.

Mar 7 '07 #4
In comp.lang.javas cript message <ZN6dnbNg08nKwX PYnZ2dnUVZ_oWdn Z2d@comcas
t.com>, Wed, 7 Mar 2007 00:31:30, McKirahan <Ne**@McKirahan .composted:
>"Eric" <er**********@g mail.comwrote in message
news:11******* *************** @8g2000cwh.goog legroups.com...
>Hello,

I have code similar to:

if (beforeToday(do cument.forms[0].sStartDate.val ue))

that was broken when an include file had a form added to it. Since my
form was no longer the 0th form, my code was broken. Is there any way
to specify a form by name or some other work around for this
situation?

Sure:

<form name="form1">

if (beforeToday(do cument.form1.sS tartDate.value) )
You are a reliable source of bad advice, here as elsewhere. Code which
works in some systems but not in others, or which is unnecessarily not
standards-compliant, is not good code.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v6.05 IE 6
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 8 '07 #5
jontyus said the following on 3/7/2007 4:31 AM:
On Mar 7, 11:57 am, scripts.cont... @gmail.com wrote:
>On Mar 7, 12:16 am, "Eric" <eric.gofo...@g mail.comwrote:
>>Hello,
I have code similar to:
if (beforeToday(do cument.forms[0].sStartDate.val ue))
Is there any way
to specify a form by name or some other work around for this
situation?
Use:
document.for ms["form_name"]
<snip>
you can use document.getEle mentById('id') to get any element.
If and only if that element has a unique ID attribute, or, you are using
a broken browser (namely, IE). Otherwise, just use the forms collection.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 10 '07 #6
Dr J R Stockton said the following on 3/8/2007 1:45 PM:
In comp.lang.javas cript message <ZN6dnbNg08nKwX PYnZ2dnUVZ_oWdn Z2d@comcas
t.com>, Wed, 7 Mar 2007 00:31:30, McKirahan <Ne**@McKirahan .composted:
>"Eric" <er**********@g mail.comwrote in message
news:11******* *************** @8g2000cwh.goog legroups.com...
>>Hello,

I have code similar to:

if (beforeToday(do cument.forms[0].sStartDate.val ue))

that was broken when an include file had a form added to it. Since my
form was no longer the 0th form, my code was broken. Is there any way
to specify a form by name or some other work around for this
situation?
Sure:

<form name="form1">

if (beforeToday(do cument.form1.sS tartDate.value) )

You are a reliable source of bad advice, here as elsewhere. Code which
works in some systems but not in others, or which is unnecessarily not
standards-compliant, is not good code.
Can you name a "system" (OS/browser) where document.formNa me won't get a
reference to the form as long as the form name doesn't contain illegal
characters? Or, is your anti-McK attitude shining through again?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 10 '07 #7

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

Similar topics

4
4300
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field that has been modified/clicked the form doesn't always submit. When it does work, a Stored procedure is passed form variables and updates to the db are made. When it doesn't, its as if the form wasn't submitted, it reloads and resets the page, but...
4
27570
by: Jan-Friedrich Mutter | last post by:
Hi, I have a problem to access a hidden field by javascript. The name of the field has a dot in it. That's the problem. But I need that dot because it is a "Stuts Property". I'm using IE 6. This is my code: <!-- function changeValue(myvalue) { //works
12
2472
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" HTML----------- Form is ----> <form action="thanks.php" method="post" name="contact_form" id="contact_form"> Name -------> <input type="text" name="name" id="name" size="25"> Button sends code -----> <input type="button" value="Submit Form"
2
2395
by: C Gillespie | last post by:
Dear All, I have 2 arrays var A1 = new Array(); A1 ="Y2"; var B1 = new Array(); B1 ="Y1"; B1 ="sink";
3
1478
by: frey | last post by:
i have two parts of code here this is a javascript: function addThirdTierCategory(){ var length = document.form.selectedCategory.options.length var maxNum=10; if(length >= maxNum){ alert('maximum selection exceeded'); return; } ....................................
3
5952
by: MeNotHome | last post by:
I am trying to automate web browser navigation and form fill out in vb.net Why doesn't this work? AxWebBrowser1.Document.Forms(0).All("action-download").click() I also tried AxWebBrowser1.Document.Forms(0).All.item("action-download").click() "action-download" is the name of a submit button
1
1154
by: John Smith | last post by:
If I have reference to some TextBox, how can I find its form name (eg. "document.Form1")?
2
1911
by: vajra1987 | last post by:
Hi guys I have the following situation: In mypage1.jsp I have 4 forms, each with a different name (and id). But on these forms, there are some fields that have the same name, for example mypage1.jsp: <form action="" name="form1" id="form1" method="POST" > <input type="hidden" name="myValFld" value=""/> .....
23
5923
by: Stanimir Stamenkov | last post by:
<form name="myForm" action="..."> <p><input type="text" name="myElem"></p> </form> As far as I was able to get the following is the standard way of accessing HTML form elements: document.forms.elements But I have also seen the following:
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.