Reference to input item as function parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hoschi-Ingo

    Reference to input item as function parameter

    Hello NG,

    I want to write a generic function to validate data in input items.
    For this I want to pass a refernce to the object which calls this function
    to read out the and modify it if nessescary. For example when having a
    date with 2 digits year it will automically changed to 4 digits.
    Also I want the opportunity to keep the focus inside this object if
    validating fails.

    I thought about this:

    function GenericCheckDat eInput( Inputitem)
    {
    var datevalue = Inputiten.value ;
    ......... //Check or generate correct date value
    Inputitem.value = datevalue;

    if (xyz)
    Inputitem.focus ();

    return whateverIwant;
    }


    <input name="Birthday" type="text" OnBlur="Generic CheckDateInput( this);">

    this doesn't work. :-(

    What I got running was: (with a corresponding function)

    <input name="Birthday" type="text" OnBlur="this.va lue =
    GenericCheckDat eInput( this.value);">

    But that's not really what I want.

    What do I have to do to get the first version running.


    Thanks
    Ingo


  • Guido Wesdorp

    #2
    Re: Reference to input item as function parameter

    Hoschi-Ingo wrote:[color=blue]
    >
    > function GenericCheckDat eInput( Inputitem)
    > {
    > var datevalue = Inputiten.value ;
    > ......... //Check or generate correct date value
    > Inputitem.value = datevalue;
    >
    > if (xyz)
    > Inputitem.focus ();
    >
    > return whateverIwant;
    > }
    >
    >
    > <input name="Birthday" type="text" OnBlur="Generic CheckDateInput( this);">
    >
    > this doesn't work. :-(
    >
    >[/color]
    Could you tell us what exactly is the error message with this setup? I
    see that you use Inputiten instead of Inputitem in the first line, isn't
    that what's wrong with the function? If not, please tell us what is so
    we know what to solve...

    Cheers,

    Guido

    Comment

    • Hoschi-Ingo

      #3
      Re: Reference to input item as function parameter


      "Guido Wesdorp" <guido@infrae.c om> schrieb im Newsbeitrag
      news:3fcdd97c$0 $214$e4fe514c@n ews.xs4all.nl.. .[color=blue]
      > Hoschi-Ingo wrote:[color=green]
      > >
      > > function GenericCheckDat eInput( Inputitem)
      > > {
      > > var datevalue = Inputiten.value ;
      > > ......... //Check or generate correct date value
      > > Inputitem.value = datevalue;
      > >
      > > if (xyz)
      > > Inputitem.focus ();
      > >
      > > return whateverIwant;
      > > }
      > >
      > >
      > > <input name="Birthday" type="text" OnBlur="Generic CheckDateInput([/color][/color]
      this);">[color=blue][color=green]
      > >
      > > this doesn't work. :-(
      > >
      > >[/color]
      > Could you tell us what exactly is the error message with this setup? I
      > see that you use Inputiten instead of Inputitem in the first line, isn't
      > that what's wrong with the function? If not, please tell us what is so
      > we know what to solve...
      >[/color]

      No that's not the problem. I didn't use copy&paste in the org function it is
      correct. There is no error message, nothing. It only does not work.
      So the question is, if it is possible to have a function like the above with
      ...(this) as parameter on calling and refer to the object passed as
      parameter.


      Comment

      • Michael Winter

        #4
        Re: Reference to input item as function parameter

        Hoschi-Ingo wrote on 03 Dec 2003:

        <snip>
        [color=blue]
        > No that's not the problem. I didn't use copy&paste in the org
        > function it is correct. There is no error message, nothing. It
        > only does not work. So the question is, if it is possible to
        > have a function like the above with ..(this) as parameter on
        > calling and refer to the object passed as parameter.[/color]

        Yes, and it usually works. What browser are you using to test this?

        You also said, "This doesn't work". That isn't sufficient. What
        didn't work? Did the value not change? Was the focus not set? Please
        be specific: you're expected results and your obtained results.

        Just as a test, I used this:

        <INPUT name="someBox" type="text" value="" onblur="testFun c(this)">

        function testFunc( control ) {
        control.value = 'someValue';
        control.focus() ;
        }

        In both Opera and IE (Win), when I clicked inside the text box, then
        on the page outside it (to remove focus), the value was inserted and
        the caret was placed inside the box.

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

        Comment

        • Hoschi-Ingo

          #5
          Re: Reference to input item as function parameter

          I don't know why, but during some further testing it suddenly worked.
          I will do some more tests to find out what exactly the problem was.
          If it is useful I will post it here


          Ingo


          "Hoschi-Ingo" <HoschiIngo@gmx .de> schrieb im Newsbeitrag
          news:bqkmo0$vd2 $04$1@news.t-online.com...[color=blue]
          >
          > "Guido Wesdorp" <guido@infrae.c om> schrieb im Newsbeitrag
          > news:3fcdd97c$0 $214$e4fe514c@n ews.xs4all.nl.. .[color=green]
          > > Hoschi-Ingo wrote:[color=darkred]
          > > >
          > > > function GenericCheckDat eInput( Inputitem)
          > > > {
          > > > var datevalue = Inputiten.value ;
          > > > ......... //Check or generate correct date value
          > > > Inputitem.value = datevalue;
          > > >
          > > > if (xyz)
          > > > Inputitem.focus ();
          > > >
          > > > return whateverIwant;
          > > > }
          > > >
          > > >
          > > > <input name="Birthday" type="text" OnBlur="Generic CheckDateInput([/color][/color]
          > this);">[color=green][color=darkred]
          > > >
          > > > this doesn't work. :-(
          > > >
          > > >[/color]
          > > Could you tell us what exactly is the error message with this setup? I
          > > see that you use Inputiten instead of Inputitem in the first line, isn't
          > > that what's wrong with the function? If not, please tell us what is so
          > > we know what to solve...
          > >[/color]
          >
          > No that's not the problem. I didn't use copy&paste in the org function it[/color]
          is[color=blue]
          > correct. There is no error message, nothing. It only does not work.
          > So the question is, if it is possible to have a function like the above[/color]
          with[color=blue]
          > ..(this) as parameter on calling and refer to the object passed as
          > parameter.
          >
          >[/color]


          Comment

          • Hoschi-Ingo

            #6
            Re: Reference to input item as function parameter


            "Michael Winter" <M.Winter@bluey onder.co.uk.inv alid> schrieb im Newsbeitrag
            news:Xns944686C 7FCD21MWinterBl ueyonder@193.38 .113.46...[color=blue]
            > Hoschi-Ingo wrote on 03 Dec 2003:
            >
            > <snip>
            >[color=green]
            > > No that's not the problem. I didn't use copy&paste in the org
            > > function it is correct. There is no error message, nothing. It
            > > only does not work. So the question is, if it is possible to
            > > have a function like the above with ..(this) as parameter on
            > > calling and refer to the object passed as parameter.[/color]
            >
            > Yes, and it usually works. What browser are you using to test this?
            >
            > You also said, "This doesn't work". That isn't sufficient. What
            > didn't work? Did the value not change? Was the focus not set? Please
            > be specific: you're expected results and your obtained results.
            >
            > Just as a test, I used this:
            >
            > <INPUT name="someBox" type="text" value="" onblur="testFun c(this)">
            >
            > function testFunc( control ) {
            > control.value = 'someValue';
            > control.focus() ;
            > }[/color]

            You're right. It works fine. I don't know why it know works. I did this test
            before an it doesn't. The only known difference is
            that in the tests before I stored the script in an external file. I will
            test external again so I can tell if this is the reason.
            But I bet 99:1 it was my fault.

            [color=blue]
            >
            > In both Opera and IE (Win), when I clicked inside the text box, then
            > on the page outside it (to remove focus), the value was inserted and
            > the caret was placed inside the box.
            >
            > Mike
            >
            > --
            > Michael Winter
            > M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)[/color]


            Comment

            • Hoschi-Ingo

              #7
              Re: Reference to input item as function parameter

              Don't know what went wrong but it works inline and as external file.
              ==> my fault.


              Ingo



              "Hoschi-Ingo" <HoschiIngo@gmx .de> schrieb im Newsbeitrag
              news:bqkojk$4uq $02$1@news.t-online.com...[color=blue]
              >
              > "Michael Winter" <M.Winter@bluey onder.co.uk.inv alid> schrieb im[/color]
              Newsbeitrag[color=blue]
              > news:Xns944686C 7FCD21MWinterBl ueyonder@193.38 .113.46...[color=green]
              > > Hoschi-Ingo wrote on 03 Dec 2003:
              > >
              > > <snip>
              > >[color=darkred]
              > > > No that's not the problem. I didn't use copy&paste in the org
              > > > function it is correct. There is no error message, nothing. It
              > > > only does not work. So the question is, if it is possible to
              > > > have a function like the above with ..(this) as parameter on
              > > > calling and refer to the object passed as parameter.[/color]
              > >
              > > Yes, and it usually works. What browser are you using to test this?
              > >
              > > You also said, "This doesn't work". That isn't sufficient. What
              > > didn't work? Did the value not change? Was the focus not set? Please
              > > be specific: you're expected results and your obtained results.
              > >
              > > Just as a test, I used this:
              > >
              > > <INPUT name="someBox" type="text" value="" onblur="testFun c(this)">
              > >
              > > function testFunc( control ) {
              > > control.value = 'someValue';
              > > control.focus() ;
              > > }[/color]
              >
              > You're right. It works fine. I don't know why it know works. I did this[/color]
              test[color=blue]
              > before an it doesn't. The only known difference is
              > that in the tests before I stored the script in an external file. I will
              > test external again so I can tell if this is the reason.
              > But I bet 99:1 it was my fault.
              >
              >[color=green]
              > >
              > > In both Opera and IE (Win), when I clicked inside the text box, then
              > > on the page outside it (to remove focus), the value was inserted and
              > > the caret was placed inside the box.
              > >
              > > Mike
              > >
              > > --
              > > Michael Winter
              > > M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)[/color]
              >
              >[/color]


              Comment

              Working...