Reference to input item as function parameter

H

Hoschi-Ingo

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
 
G

Guido Wesdorp

Hoschi-Ingo said:
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
 
H

Hoschi-Ingo

Guido Wesdorp said:
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.
 
H

Hoschi-Ingo

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
 
M

Michael Winter

Hoschi-Ingo wrote on 03 Dec 2003:

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
 
H

Hoschi-Ingo

Michael Winter said:
Hoschi-Ingo wrote on 03 Dec 2003:



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

Hoschi-Ingo

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


Ingo



Hoschi-Ingo said:
Hoschi-Ingo wrote on 03 Dec 2003:



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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top