473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 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
6 6066
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

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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: Riccardo Rossi | last post by:
Hi all! How does Python pass arguments to a function? By value or by reference? Thanks, Riccardo Rossi.
10
by: crjunk | last post by:
I have a script that I want to run only when my input box IS NOT disabled. Can someone tell me if something is wrong with my script? Is "disabled" the correct property to use? function...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
6
by: T Koster | last post by:
After a few years of programming C, I had come to believe that I finally knew how to correctly organise my structure definitions in header files for mutually dependent structures, but I find myself...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
10
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to initialize a 'const Derived1 &output'. If the...
4
by: kasthurirangan.balaji | last post by:
Hi, Recently i came across a functiion declaration as below void f(char *&a); Nowhere i have come across this style. I understand, passing by reference is always better(to avoid copying),...
0
by: smnsolomon | last post by:
Hey, I have a database interaction file in vb. net where in I am connecting to database and I am inserting the image files in the SQL server 2005 database. The Code works fine on my machine but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.