help

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

    help

    I tried this in <input name="some_name " type="text" value=""
    onChange="auto_ select(0);">

    but it gives a syntax error.


    var cb = this.form.name
    alert( "name=" + cb )


    --
    -------------------------------------------------------
    Remove .NOSPAM from my email address to reply directly.
  • Ivo

    #2
    Re: syntax error, help

    "Bob" wrote[color=blue]
    > I tried this in <input name="some_name " type="text" value=""
    > onChange="auto_ select(0);">
    >
    > but it gives a syntax error.
    >
    >
    > var cb = this.form.name
    > alert( "name=" + cb )[/color]

    Hello Bob, not sure what you are trying to achieve here, but there are a
    couple of things we can do about that. Could you please explain what you
    would like to happen, what happens instead, and perhaps provide a bit more
    code because it seems we are missing some relevant pieces. What is
    auto_select(), are you sure the element referenced as "this" comes through
    correctly?
    Also 'help' isn't the most helpful subject line .
    HTH
    Ivo


    Comment

    • kaeli

      #3
      Re: help

      In article <tHjxc.27261$sS 2.823079@news20 .bellglobal.com >,
      bob.lockie.NOSP AM@mail.com enlightened us with...[color=blue]
      > I tried this in <input name="some_name " type="text" value=""
      > onChange="auto_ select(0);">
      >
      > but it gives a syntax error.
      >
      >
      > var cb = this.form.name[/color]

      'this', in a function, might not refer to what you thought it referred
      to. I don't think it refers to the control, which is what that code
      _seems_ to be thinking.

      Post more code or a URL.

      --
      --
      ~kaeli~
      Why do people who know the least know it the loudest?



      Comment

      • Bob

        #4
        Re: syntax error, help

        On 06/08/04 10:29 Ivo spoke:[color=blue]
        > "Bob" wrote
        >[color=green]
        >>I tried this in <input name="some_name " type="text" value=""
        >>onChange="aut o_select(0);">
        >>
        >>but it gives a syntax error.
        >>
        >>
        >> var cb = this.form.name
        >> alert( "name=" + cb )[/color]
        >
        >
        > Hello Bob, not sure what you are trying to achieve here, but there are a
        > couple of things we can do about that. Could you please explain what you
        > would like to happen, what happens instead, and perhaps provide a bit more
        > code because it seems we are missing some relevant pieces. What is
        > auto_select(), are you sure the element referenced as "this" comes through
        > correctly?[/color]

        function auto_select() {
        // var cb = this.forms[0].elements["some_name"].name
        var cb = this.form.name

        alert( "name=" + cb )
        }

        I want to call auto_select when text is changed in the text field.
        I tried var cb = this().form.nam e but I got "object is not function.



        --
        -------------------------------------------------------
        Remove .NOSPAM from my email address to reply directly.

        Comment

        • Lee

          #5
          Re: syntax error, help

          Bob said:[color=blue]
          >
          >On 06/08/04 10:29 Ivo spoke:[color=green]
          >> "Bob" wrote
          >>[color=darkred]
          >>>I tried this in <input name="some_name " type="text" value=""
          >>>onChange="au to_select(0);">
          >>>
          >>>but it gives a syntax error.
          >>>
          >>>
          >>> var cb = this.form.name
          >>> alert( "name=" + cb )[/color]
          >>
          >>
          >> Hello Bob, not sure what you are trying to achieve here, but there are a
          >> couple of things we can do about that. Could you please explain what you
          >> would like to happen, what happens instead, and perhaps provide a bit more
          >> code because it seems we are missing some relevant pieces. What is
          >> auto_select(), are you sure the element referenced as "this" comes through
          >> correctly?[/color]
          >
          >function auto_select() {
          >// var cb = this.forms[0].elements["some_name"].name
          > var cb = this.form.name
          >
          > alert( "name=" + cb )
          >}
          >
          >I want to call auto_select when text is changed in the text field.
          >I tried var cb = this().form.nam e but I got "object is not function.[/color]

          What are you trying to find the name of, the text field, or the
          form that contains it? You've come closest to getting the name
          of the form, but I'm not sure that's what you want.

          In that context "this" refers to auto_select(), not the form field.
          In the context of the onchange event handler function, "this" does
          refer to the field, so you can have that function pass the reference
          to auto_select():

          <input name="some_name "
          type="text"
          value=""
          onchange="auto_ select(this)">

          function auto_select(fie ld) {
          var cb = field.name
          alert( "name=" + cb )
          }

          Comment

          • Bob

            #6
            Re: syntax error, help

            > What are you trying to find the name of, the text field, or the[color=blue]
            > form that contains it? You've come closest to getting the name
            > of the form, but I'm not sure that's what you want.[/color]

            I want the name of the text field.

            [color=blue]
            >
            > In that context "this" refers to auto_select(), not the form field.
            > In the context of the onchange event handler function, "this" does
            > refer to the field, so you can have that function pass the reference
            > to auto_select():
            >
            > <input name="some_name "
            > type="text"
            > value=""
            > onchange="auto_ select(this)">
            >
            > function auto_select(fie ld) {
            > var cb = field.name
            > alert( "name=" + cb )
            > }
            >[/color]

            Thanks, got it.


            --
            -------------------------------------------------------
            Remove .NOSPAM from my email address to reply directly.

            Comment

            • Bob

              #7
              Re: syntax error, help

              function auto_select( field, index ) {
              var cb = field.form.elem ents["selectID"].name

              alert( "name=" + cb )
              }


              </script>

              <input name="content_2 16" type="text" value="1" onChange="auto_ select(
              this, 0);">

              <input name="content_2 17" type="text" value="2" onChange="auto_ select(
              this, 0);">

              <input name="selectID" value="216" type="checkbox" >
              <input name="selectID" value="217" type="checkbox" >

              There is a corresponding checkbox for every text entry field and what I
              want is to make the checkbox selected if the text is changed.



              --
              -------------------------------------------------------
              Remove .NOSPAM from my email address to reply directly.

              Comment

              • Lee

                #8
                Re: syntax error, help

                Bob said:[color=blue]
                >
                >function auto_select( field, index ) {
                > var cb = field.form.elem ents["selectID"].name
                >
                > alert( "name=" + cb )
                >}
                >
                >
                ></script>
                >
                ><input name="content_2 16" type="text" value="1" onChange="auto_ select(
                >this, 0);">
                >
                ><input name="content_2 17" type="text" value="2" onChange="auto_ select(
                >this, 0);">
                >
                ><input name="selectID" value="216" type="checkbox" >
                ><input name="selectID" value="217" type="checkbox" >
                >
                >There is a corresponding checkbox for every text entry field and what I
                >want is to make the checkbox selected if the text is changed.[/color]

                Here's one way, assuming that you mean "checked" when you say "selected".
                It might help to know what you're really trying to do.
                Do you really need all of the checkboxes to have the same name attribute?
                Does it matter if more than one checkbox is checked?


                <html>
                <head>
                <script type="text/javascript">
                function auto_select(fie ld) {
                var cb=field.name.r eplace(/^content/,"select");
                document.getEle mentById(cb).ch ecked=true;
                }
                </script>
                </head>
                <body>
                <form>
                <input name="content_2 16" type="text" value="1" onchange="auto_ select(this)">
                <input name="selectID" value="216" id="select_216 " type="checkbox" >
                <br>
                <input name="content_2 17" type="text" value="2" onchange="auto_ select(this)">
                <input name="selectID" value="217" id="select_217 " type="checkbox" >
                </form>
                </body>
                </html>

                Comment

                • Bob

                  #9
                  Re: syntax error, help


                  I mean "checked" when you said "selected".
                  [color=blue]
                  > It might help to know what you're really trying to do.[/color]

                  I have x number of text fields each paired with a checkbox.
                  When a text field is changed I want to automatically select the
                  corresponding checkbox.

                  [color=blue]
                  > Do you really need all of the checkboxes to have the same name attribute?[/color]

                  There is a dynamic number of them (but each one is paired with a text
                  field with a unique "value") and I can iterate through each checkbox
                  (and find the corresponding text value) on the server in PHP if they
                  have the same name.
                  There is no guarantee that the unique values will be in sequence either.

                  The id= is used to uniquely identify the checkbox and the id is built
                  from the field name?

                  [color=blue]
                  > Does it matter if more than one checkbox is checked?[/color]

                  Yes, more than one checkbox can be checked.[color=blue]
                  >
                  >
                  > <html>
                  > <head>
                  > <script type="text/javascript">
                  > function auto_select(fie ld) {
                  > var cb=field.name.r eplace(/^content/,"select");
                  > document.getEle mentById(cb).ch ecked=true;
                  > }[/color]

                  Thank you, it seems to do exactly what I want.


                  --
                  -------------------------------------------------------
                  Remove .NOSPAM from my email address to reply directly.

                  Comment

                  Working...