Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Reference to input item as function parameter

Reply
Thread Tools

Reference to input item as function parameter

 
 
Hoschi-Ingo
Guest
Posts: n/a
 
      12-03-2003
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


 
Reply With Quote
 
 
 
 
Guido Wesdorp
Guest
Posts: n/a
 
      12-03-2003
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

 
Reply With Quote
 
 
 
 
Hoschi-Ingo
Guest
Posts: n/a
 
      12-03-2003

"Guido Wesdorp" <(E-Mail Removed)> schrieb im Newsbeitrag
news:3fcdd97c$0$214$(E-Mail Removed)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.


 
Reply With Quote
 
Hoschi-Ingo
Guest
Posts: n/a
 
      12-03-2003
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" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bqkmo0$vd2$04$(E-Mail Removed)-online.com...
>
> "Guido Wesdorp" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:3fcdd97c$0$214$(E-Mail Removed)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.
>
>



 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      12-03-2003
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
http://www.velocityreviews.com/forums/(E-Mail Removed)d (remove ".invalid" to reply)
 
Reply With Quote
 
Hoschi-Ingo
Guest
Posts: n/a
 
      12-03-2003

"Michael Winter" <(E-Mail Removed)> 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
> (E-Mail Removed)d (remove ".invalid" to reply)



 
Reply With Quote
 
Hoschi-Ingo
Guest
Posts: n/a
 
      12-03-2003
Don't know what went wrong but it works inline and as external file.
==> my fault.


Ingo



"Hoschi-Ingo" <(E-Mail Removed)> schrieb im Newsbeitrag
news:bqkojk$4uq$02$(E-Mail Removed)-online.com...
>
> "Michael Winter" <(E-Mail Removed)> 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
> > (E-Mail Removed)d (remove ".invalid" to reply)

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
decltype as a template parameter when containing reference to anothertemplate parameter. Isti C++ 2 04-19-2010 10:01 PM
How to pass a parameter for a function parameter in a function AzamSharp Javascript 2 07-05-2008 12:24 AM
How can I keep reference to an input parameter of a function? Allerdyce.John@gmail.com C++ 4 02-27-2006 04:57 PM
Passing HttpContext reference as an input parameter josephpage@gmail.com ASP .Net 1 04-13-2005 11:38 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments