By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

Reference to input item as function parameter

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Jul 20 '05 #2

P: n/a

"Guido Wesdorp" <gu***@infrae.com> schrieb im Newsbeitrag
news:3f*********************@news.xs4all.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.
Jul 20 '05 #3

P: n/a
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
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #4

P: n/a
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" <Ho********@gmx.de> schrieb im Newsbeitrag
news:bq*************@news.t-online.com...

"Guido Wesdorp" <gu***@infrae.com> schrieb im Newsbeitrag
news:3f*********************@news.xs4all.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.

Jul 20 '05 #5

P: n/a

"Michael Winter" <M.******@blueyonder.co.uk.invalid> schrieb im Newsbeitrag
news:Xn*******************************@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
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)

Jul 20 '05 #6

P: n/a
Don't know what went wrong but it works inline and as external file.
==> my fault.
Ingo

"Hoschi-Ingo" <Ho********@gmx.de> schrieb im Newsbeitrag
news:bq*************@news.t-online.com...

"Michael Winter" <M.******@blueyonder.co.uk.invalid> schrieb im Newsbeitrag news:Xn*******************************@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
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)


Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.