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

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 5664
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.getElementById('formId') 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.getElementById("alpha");
alert(a.beta.value);
</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.getElementsByName("element_name")[zero_based_index]

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
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...
13
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...
6
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...
4
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...
4
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...
3
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...
4
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...
4
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...
5
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...
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.