Hello! I have a nice little problem :)
I am using PHP to create input fields on a page, and a trick in PHP to have the
result end up in an array is to name the field like "field[foo]".
However, sometimes I need to act on these fields with a javascript, but as far
as I know, you can't do this:
<input type='text' name='field[foo]' />
<script language='javascript'>
document.form.field[foo].value = "bar"
</script>
Since that looks for the foo-entry in the field-array, right?
So how do I refer to the "field[foo]" field in a script?
--
Sandman[.net] 6 4805
Hello,
Try this:
<body>
<form name='f'>
<input type='button' name='x[]' onclick='accessme(this.form)' value='Hey!'>
</form>
<script>
function accessme(frm)
{
alert(frm.elements['x[]'].value);
}
</script>
</body>
"Sandman" <mr@sandman.net> wrote in message
news:mr**********************@news.fu-berlin.de... Hello! I have a nice little problem :)
I am using PHP to create input fields on a page, and a trick in PHP to
have the result end up in an array is to name the field like "field[foo]".
However, sometimes I need to act on these fields with a javascript, but as
far as I know, you can't do this:
<input type='text' name='field[foo]' />
<script language='javascript'> document.form.field[foo].value = "bar" </script>
Since that looks for the foo-entry in the field-array, right?
So how do I refer to the "field[foo]" field in a script?
-- Sandman[.net]
Sandman wrote: Hello! I have a nice little problem :)
I am using PHP to create input fields on a page, and a trick in PHP to have the result end up in an array is to name the field like "field[foo]".
However, sometimes I need to act on these fields with a javascript, but as far as I know, you can't do this:
<input type='text' name='field[foo]' />
<script language='javascript'>
language attribute is deprecated, use type="text/javascript" instead.
Its irrelevant to your problem though.
document.form.field[foo].value = "bar" </script>
Since that looks for the foo-entry in the field-array, right?
So how do I refer to the "field[foo]" field in a script? http://www.jibbering.com/faq/#FAQ4_39
--
Randy
Chance Favors The Prepared Mind
In article <Ld********************@comcast.com>,
Randy Webb <hi************@aol.com> wrote: document.form.field[foo].value = "bar" </script>
Since that looks for the foo-entry in the field-array, right?
So how do I refer to the "field[foo]" field in a script? http://www.jibbering.com/faq/#FAQ4_39
Uh, so that means:
document.form["field[]"].value ?
--
Sandman[.net]
Sandman wrote: In article <Ld********************@comcast.com>, Randy Webb <hi************@aol.com> wrote:
document.form.field[foo].value = "bar" </script>
Since that looks for the foo-entry in the field-array, right?
So how do I refer to the "field[foo]" field in a script? http://www.jibbering.com/faq/#FAQ4_39
Uh, so that means:
document.form["field[]"].value ?
Close:
document.forms['formName'].elements['field[]'].value
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
In article <I-********************@comcast.com>,
Randy Webb <hi************@aol.com> wrote: Uh, so that means:
document.form["field[]"].value ?
Close:
document.forms['formName'].elements['field[]'].value
Aaah, that worked! You actually had to refer to it by the elements[] - I only
thought this was a way to escape names, so if you have an object named 'foo[]'
then you could refer to it by document['foo[]'] - but apprently not. :)
Thanks!
--
Sandman[.net]
Sandman wrote: In article <I-********************@comcast.com>, Randy Webb <hi************@aol.com> wrote:
Uh, so that means:
document.form["field[]"].value ?
Close:
document.forms['formName'].elements['field[]'].value
Aaah, that worked! You actually had to refer to it by the elements[] - I only thought this was a way to escape names, so if you have an object named 'foo[]' then you could refer to it by document['foo[]'] - but apprently not. :)
Glad you got it figured out.
window['foo[]'] will work in some instances, as will document['foo[]']
but using, or attempting to use, that notation, without understanding
its implications/uses will cause you more problems than it will ever
solve. :-)
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J.R |
last post by:
Greetings,
I'm adding dynamically created input type='file' controls via JavaScript.
However when I try to access they do not seem to be returned in the form
collection. Any ideas?
Thanks,...
|
by: Perdit |
last post by:
I am wondering why this does not work in javascript. The html color is
set to automatic (none)
element1, element2, etc are input fields (textboxes)
...
|
by: williamc |
last post by:
Somebody asked me if it would be possible to add auto-advance to a web
form where there are a lot of repetitive 5 character fields. I took a
look around the web and found a script, which appears to...
|
by: Michael Bulatovich |
last post by:
I have a simple db to keep track of work/time/projects etc. It has two
fields (column) named "start time" and "end time"
WITH THE SPACES. I'm trying to do some automation to a form associated with...
|
by: John |
last post by:
Hi
What would be the input mask for a name field where first letter is caps and
the rest lower? Its ideal if the mask can handle multiple names separated by
a space but if not a single word will...
|
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
|
by: christianlott1 |
last post by:
I want to provide users with an interface to create a custom merge
(all in Access, not Word). User will put in a set of brackets ("<>")
in a memo field and when they click the merge button it will...
|
by: Wayne |
last post by:
I have been given the task of rewriting a database that seems as
though it has been written by someone with a very basic understanding
of Access. Many of the object names and field names in tables...
|
by: cront |
last post by:
I have a problem to work on:
we will ask user to input anything and we will put that back onto the
standard output with all set of brackets removed. We will not remove any
single bracket e.g.
...
|
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: 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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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: 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...
|
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,...
|
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...
| |