Reference to input item as function parameter

Discussion in 'Javascript' started by Hoschi-Ingo, Dec 3, 2003.

  1. Hoschi-Ingo

    Hoschi-Ingo Guest

    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 GenericCheckDateInput( 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="GenericCheckDateInput( this);">

    this doesn't work. :-(

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

    <input name="Birthday" type="text" OnBlur="this.value =
    GenericCheckDateInput( this.value);">

    But that's not really what I want.

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


    Thanks
    Ingo
     
    Hoschi-Ingo, Dec 3, 2003
    #1
    1. Advertising

  2. Hoschi-Ingo wrote:
    >
    > function GenericCheckDateInput( 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="GenericCheckDateInput( this);">
    >
    > this doesn't work. :-(
    >
    >

    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
     
    Guido Wesdorp, Dec 3, 2003
    #2
    1. Advertising

  3. Hoschi-Ingo

    Hoschi-Ingo Guest

    "Guido Wesdorp" <> schrieb im Newsbeitrag
    news:3fcdd97c$0$214$4all.nl...
    > Hoschi-Ingo wrote:
    > >
    > > function GenericCheckDateInput( 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="GenericCheckDateInput(

    this);">
    > >
    > > this doesn't work. :-(
    > >
    > >

    > 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...
    >


    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.
     
    Hoschi-Ingo, Dec 3, 2003
    #3
  4. Hoschi-Ingo

    Hoschi-Ingo Guest

    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" <> schrieb im Newsbeitrag
    news:bqkmo0$vd2$04$-online.com...
    >
    > "Guido Wesdorp" <> schrieb im Newsbeitrag
    > news:3fcdd97c$0$214$4all.nl...
    > > Hoschi-Ingo wrote:
    > > >
    > > > function GenericCheckDateInput( 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="GenericCheckDateInput(

    > this);">
    > > >
    > > > this doesn't work. :-(
    > > >
    > > >

    > > 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...
    > >

    >
    > 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.
    >
    >
     
    Hoschi-Ingo, Dec 3, 2003
    #4
  5. Hoschi-Ingo wrote on 03 Dec 2003:

    <snip>

    > 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.


    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="testFunc(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
    d (remove ".invalid" to reply)
     
    Michael Winter, Dec 3, 2003
    #5
  6. Hoschi-Ingo

    Hoschi-Ingo Guest

    "Michael Winter" <> schrieb im Newsbeitrag
    news:Xns944686C7FCD21MWinterBlueyonder@193.38.113.46...
    > Hoschi-Ingo wrote on 03 Dec 2003:
    >
    > <snip>
    >
    > > 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.

    >
    > 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="testFunc(this)">
    >
    > function testFunc( control ) {
    > control.value = 'someValue';
    > control.focus();
    > }


    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.


    >
    > 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
    > d (remove ".invalid" to reply)
     
    Hoschi-Ingo, Dec 3, 2003
    #6
  7. Hoschi-Ingo

    Hoschi-Ingo Guest

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


    Ingo



    "Hoschi-Ingo" <> schrieb im Newsbeitrag
    news:bqkojk$4uq$02$-online.com...
    >
    > "Michael Winter" <> schrieb im

    Newsbeitrag
    > news:Xns944686C7FCD21MWinterBlueyonder@193.38.113.46...
    > > Hoschi-Ingo wrote on 03 Dec 2003:
    > >
    > > <snip>
    > >
    > > > 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.

    > >
    > > 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="testFunc(this)">
    > >
    > > function testFunc( control ) {
    > > control.value = 'someValue';
    > > control.focus();
    > > }

    >
    > 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.
    >
    >
    > >
    > > 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
    > > d (remove ".invalid" to reply)

    >
    >
     
    Hoschi-Ingo, Dec 3, 2003
    #7
    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. Replies:
    1
    Views:
    1,035
    Karl Seguin
    Apr 14, 2005
  2. Replies:
    4
    Views:
    304
    Tomás
    Feb 27, 2006
  3. Isti
    Replies:
    2
    Views:
    726
  4. Mister B
    Replies:
    8
    Views:
    554
    Nick Keighley
    Aug 26, 2010
  5. AzamSharp
    Replies:
    2
    Views:
    181
Loading...

Share This Page