Howto point to a textbox?

Discussion in 'Javascript' started by Richard Salin, Nov 2, 2004.

  1. 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
     
    Richard Salin, Nov 2, 2004
    #1
    1. Advertising

  2. On Wed, 3 Nov 2004 00:43:49 +0200, Richard Salin <>
    wrote:

    [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 (<URL:http://jibbering.com/faq/>).

    > 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

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Nov 2, 2004
    #2
    1. Advertising

  3. A bit more help please...

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


    > On Wed, 3 Nov 2004 00:43:49 +0200, Richard Salin <>
    > wrote:
    >
    > [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 (<URL:http://jibbering.com/faq/>).
    >
    >> 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
    >
    > --
    > Michael Winter
    > Replace ".invalid" with ".uk" to reply by e-mail.


    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
     
    Richard Salin, Nov 2, 2004
    #3
  4. Re: A bit more help please...

    On Wed, 3 Nov 2004 01:29:28 +0200, Richard Salin <>
    wrote:

    [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

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
     
    Michael Winter, Nov 2, 2004
    #4
  5. Thanks alot! [nt]

    "Michael Winter" <> kirjoitti
    viestissä:eek:psgu2w8lkx13kvk@atlantis...
    > On Wed, 3 Nov 2004 01:29:28 +0200, Richard Salin <>
    > wrote:
    >
    > [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
    >
    > --
    > Michael Winter
    > Replace ".invalid" with ".uk" to reply by e-mail.
     
    Richard Salin, Nov 3, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gopi

    point to point protocol

    Gopi, Jul 13, 2004, in forum: VHDL
    Replies:
    1
    Views:
    499
    Mike Treseler
    Jul 13, 2004
  2. H aka N
    Replies:
    15
    Views:
    15,829
    Ben Jones
    Mar 2, 2006
  3. Motaz Saad
    Replies:
    7
    Views:
    6,554
  4. USCode
    Replies:
    7
    Views:
    446
    jeffc
    Jul 9, 2004
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,417
    Saraswati lakki
    Jan 6, 2012
Loading...

Share This Page