form property and object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mathieu gagnon

    form property and object

    Hello,

    I'm new to this newsgroup and I have small question.

    With something like this : <form name="a"><input name="name"></form>
    Is it possible to get the name of the form (a) and access the input object
    (name) too ?

    Thanks,
    /mathieu



  • HikksNotAtHome

    #2
    Re: form property and object

    In article <gIa1b.59997$PD 3.4617102@nnrp1 .uunet.ca>, "mathieu gagnon"
    <matt@netc.ne t> writes:
    [color=blue]
    >I'm new to this newsgroup and I have small question.
    >
    >With something like this : <form name="a"><input name="name"></form>
    >Is it possible to get the name of the form (a) and access the input object
    >(name) too ?
    >
    >Thanks,
    >/mathieu[/color]


    <form name="myForm">
    <input type="button" onclick="alert( this.form.name) "
    value="Click Me to see the Forms Name">
    <input type="button" onclick="alert( this.name)"
    value="Click Me to see My Name" name="myInput">
    <input type="button"
    onclick="alert( 'This input is in the ' + this.form.name + ' form. And my
    input name is ' + this.name)"
    value="Click Me to see the Forms Name and My Name" name="myInput2" >
    </form>

    alert(document. forms[0].elements[1].name)
    alert(document. forms[0].name)

    In short, you access the form elements name property, or the elements name
    property.

    HTH
    --
    Randy
    All code posted is dependent upon the viewing browser
    supporting the methods called, and Javascript being enabled.

    Comment

    • Mathieu Gagnon

      #3
      Re: form property and object

      If I try...

      <form name="a"><input name="name"></form>
      alert(document. forms[0].elements[1].name)
      alert(document. forms[0].name)

      The first alert gives "name", the second : "[object]".
      What I need is "a" alerted without changing the name of the input.

      Thanks,
      /mathieu

      "HikksNotAtHome " <hikksnotathome @aol.com> a écrit dans le message de
      news:2003082118 4853.11022.0000 0117@mb-m14.aol.com...[color=blue]
      > In article <gIa1b.59997$PD 3.4617102@nnrp1 .uunet.ca>, "mathieu gagnon"
      > <matt@netc.ne t> writes:
      >[color=green]
      > >I'm new to this newsgroup and I have small question.
      > >
      > >With something like this : <form name="a"><input name="name"></form>
      > >Is it possible to get the name of the form (a) and access the input[/color][/color]
      object[color=blue][color=green]
      > >(name) too ?
      > >
      > >Thanks,
      > >/mathieu[/color]
      >
      >
      > <form name="myForm">
      > <input type="button" onclick="alert( this.form.name) "
      > value="Click Me to see the Forms Name">
      > <input type="button" onclick="alert( this.name)"
      > value="Click Me to see My Name" name="myInput">
      > <input type="button"
      > onclick="alert( 'This input is in the ' + this.form.name + ' form. And my
      > input name is ' + this.name)"
      > value="Click Me to see the Forms Name and My Name" name="myInput2" >
      > </form>
      >
      > alert(document. forms[0].elements[1].name)
      > alert(document. forms[0].name)
      >
      > In short, you access the form elements name property, or the elements name
      > property.
      >
      > HTH
      > --
      > Randy
      > All code posted is dependent upon the viewing browser
      > supporting the methods called, and Javascript being enabled.[/color]


      Comment

      • HikksNotAtHome

        #4
        Re: form property and object

        In article <ySc1b.60056$PD 3.4617784@nnrp1 .uunet.ca>, "Mathieu Gagnon"
        <matt@netc.ne t> writes:
        [color=blue]
        >If I try...
        >
        ><form name="a"><input name="name"></form>
        >alert(document .forms[0].elements[1].name)
        >alert(document .forms[0].name)
        >
        >The first alert gives "name", the second : "[object]".
        >What I need is "a" alerted without changing the name of the input.
        >[/color]

        The reason you are getting object is because you have a form input named "name"
        and as such, instead of trying to access the form's name property, it is
        accessing the field element named name, which is an object. Thats part of why
        you should never name form inputs (or ids, or classes), the same as an HTML
        attribute.

        If you are going to try to access the name of a form that has an input named
        name,
        you may want to try renaming the input, programatticall y, and then renaming it
        after getting the form name:

        document.forms[0].elements["name"].name = "someThingElse" ;
        alert(document. forms[0].name);
        document.forms[0].elements["someThingE lse"].name = "name"

        Another alternative, if you are just dead set on having it named "name", is to
        capitalize it "Name" and then it won't interfere.

        HTH

        --
        Randy
        All code posted is dependent upon the viewing browser
        supporting the methods called, and Javascript being enabled.

        Comment

        Working...