Howto point to a textbox?

R

Richard Salin

Hi
I just wondered how I can refer to the following two
textboxes in this form:

<FORM action="FormWrite.php" method="post" name="submitForm">
<INPUT NAME="inputValues[etunimi]" SIZE=40>
<INPUT NAME="inputValues[sukunimi]" SIZE=40>
<INPUT TYPE="button" onclick="javacscript:sendForm();"
VALUE="Lähetä">
</FORM>


the reason the [] signs are in the name is to get all the textboxes values
in one variable
when using a php script.

- But how can I refer to it with javascript? For example; I tried

alert(document.submitForm.inputValues[etunimi].value);

....but it doesn't work. Can anyone tell me how this is done?
Thanks in advance!

Richard
 
M

Michael Winter

[snip]
<INPUT NAME="inputValues[etunimi]" SIZE=40>
<INPUT NAME="inputValues[sukunimi]" SIZE=40>
[snip]

- But how can I refer to it with javascript? [...]

Please read the FAQ ( said:
alert(document.submitForm.inputValues[etunimi].value);

...but it doesn't work.

No, that certainly wouldn't. The square bracket notation is used to access
properties. In addition to the relevant article in the Quick Answers
section of the FAQ, you might want to read this article in the FAQ notes:
<URL:http://www.jibbering.com/faq/faq_notes/square_brackets.html>.

[snip]

Hope that helps,
Mike
 
R

Richard Salin

----- Original Message -----
From: "Michael Winter" <[email protected]>
Newsgroups: comp.lang.javascript
Sent: Wednesday, November 03, 2004 1:19 AM
Subject: Re: Howto point to a textbox?

[snip]
<INPUT NAME="inputValues[etunimi]" SIZE=40>
<INPUT NAME="inputValues[sukunimi]" SIZE=40>
[snip]

- But how can I refer to it with javascript? [...]

Please read the FAQ ( said:
alert(document.submitForm.inputValues[etunimi].value);

...but it doesn't work.

No, that certainly wouldn't. The square bracket notation is used to access
properties. In addition to the relevant article in the Quick Answers
section of the FAQ, you might want to read this article in the FAQ notes:
<URL:http://www.jibbering.com/faq/faq_notes/square_brackets.html>.

[snip]

Hope that helps,
Mike

The link was very informative, thanks for that, but I haven't figured out
how I could refer directly to the boxes.
I wouldn't want to change their names since the php
script is builded to support those names.
Is it possible to refer to the names with the square brackets? and if so
how?
Thanks again!

Richard
 
M

Michael Winter

[snip]
Is it possible to refer to the names with the square brackets? and if so
how?

Yes. :)

var form = document.forms['submitForm'];
var etunimi = form.elements['inputValues[etunimi]'];
var sukunimi = form.elements['inputValues[sukunimi]'];

Good luck,
Mike
 
R

Richard Salin

Michael Winter said:
[snip]
Is it possible to refer to the names with the square brackets? and if so
how?

Yes. :)

var form = document.forms['submitForm'];
var etunimi = form.elements['inputValues[etunimi]'];
var sukunimi = form.elements['inputValues[sukunimi]'];

Good luck,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top