473,770 Members | 7,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't select form using getElementById

I haven't been able to select a form using getElementById. I only can
select a form using the "name" property of the <form> tag. Is there
another way to select a form, or is it even possible to use getElementById
to select a particular form?

--
Thanks,

Justin.
http://www.opera.com/mail/
Jul 23 '05 #1
3 5696
Justin Sane wrote:
I haven't been able to select a form using getElementById. I only can
select a form using the "name" property of the <form> tag. Is there
another way to select a form, or is it even possible to use getElementById
to select a particular form?


Using document.getEle mentById('formI d') should work, but
document.forms['formId'] is probably better supported.

The majority of things people want to do with forms are usually easier to do
with "this" in a form element event handler or "this.form" in an form
control event handler.

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #2
Lee
Justin Sane said:

I haven't been able to select a form using getElementById. I only can
select a form using the "name" property of the <form> tag. Is there
another way to select a form, or is it even possible to use getElementById
to select a particular form?


Yes, it's possible.
Does your form have an ID attribute? What browser(s)?
Show a small test case that fails.
The following works in IE and Firefox:

<html>
<body>
<form name="alpha" id="alpha">
<input name="beta" value="gamma">
</form>
<script type="text/javascript">
var a=document.getE lementById("alp ha");
alert(a.beta.va lue);
</script>
</body>
</html>

Jul 23 '05 #3
Justin Sane wrote:
I haven't been able to select a form using getElementById. I only
can select a form using the "name" property of the <form> tag.
Probably you mean the `name' attribute of the `form' element.
Markup elements, which consist of (a) tag(s) and sometimes
non-empty content, have attributes; objects have properties.
Is there another way to select a form, or is it even possible to
use getElementById to select a particular form?


1. name != ID. If you use names, use

document.getEle mentsByName("el ement_name")[zero_based_inde x]

2. Use the both standards compliant and downwards compatible

document.forms["form_name"]

reference or any shortcut of it (`this.form' suffices in
an event handler attribute value of a form control that
is decendant of a `form' element.)

3. This question was not new. Please read previous discussions before
posting.

4. Despite what the provider tells you, me@privacy.net is not an
(existing) e-mail address and so using it in the From or Reply-To
header is a violation of Internet protocols as well as a disregard
of (Usenet) Netiquette. Stop using it and start maintaining your
inbox.
PointedEars
Jul 23 '05 #4

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

Similar topics

15
15481
by: TJ Walls | last post by:
Hello All, Is it possible to create a <select> element with no selected options? I have tried setting the selectedIndex attribute to -1, but as far as I can tell this only works for <select multiple> elements. Am I missing something obvious? Sincerely, TJ Walls
13
2366
by: LRW | last post by:
Having a problem getting a onSubmit function to work, to where it popsup a confirmation depending on which radiobutton is selected. Here's what I have: function checkdel() { if (document.getElementById"].value=='1') { confirm('Are you sure you want to delete this file?'); } } ......
6
8338
by: rajesh | last post by:
Is it possible to display the select box without scrollbar in my program there is a need for that . The code attached below contains 2 select box and four buttons and the button is used to interchange the data's in the select box. (provuide coding for no scrollbar in select box) Thank You in advance
4
2477
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the value of an option in a select statement: <select id="usertypes" multiple="multiple"> <option value="0033">data1</option>
4
2436
by: gregincolumbus | last post by:
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes. Ideally, a change of select1 1. trigger the population of select2 (and set it initially to 0) 2. make the text fields disappear 3. trigger the financial calculation to reflect the select1 choice. Any help would be greatly appeciated !
3
2927
by: matwilko | last post by:
hi, i am trying to create a simple version of itunes...and i am using iframes to do this. I have already set up the iframes using dreamweaver and used a drop-down menu to select the genre. When selecting the genre the artists appears in iframe1...and i want to be able to select the artist so that the songs appear. I am unsure of how to do this, could anybody help? Thanks Here is my current code... <html> <head> <title>MiTunes</title>...
4
4587
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
4
20461
by: cptuser | last post by:
Hi, I have an online form which has a select element, which I;m using very basic JS to enable and disable a select element based on the selection of another select element. For some reason, the JS disables the select element correctly, but it does not re-enable it. Could someone please help with the right code. here is the Javascript code. function annconf() {
5
4466
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
9592
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
10230
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
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...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6678
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
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
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.