[jQuery] Re: Form Input Lookup

2007-08-31 Thread Phunky

Thanks for the reply Pyro, i managed to get something working but i
have a feeling it quite bloated way of doing it...


http://pastebin.com/m7d942a29

The above links to the code snippet that i created, it checks a URL
that returns either "match" or "null" depending if it finds a match
for the selected text and then depending on the results changes the
styling of the element.

I have a funny feeling im not doing it the best way possible but then
im very bad at JS :D



[jQuery] Re: Form Input Lookup

2007-08-30 Thread Pyrolupus

> 1: Grab the value of a form input
> 2: Grab results of a .php page via AJAX ( $.get()?? )
> 3: Check through the AJAX results ( should i return the data as JSON?
> or just | it? )
> 4: If there is a match / likeness for what is in the form input
> addClass('error') IF NOT addClass('accept')
...
> Thanks for the replies i am actually using the autocomplete plugin for
> my live search parts, but what im trying to create is just a lookup
> which will not return any selection values but just addClass depending
> what it finds.

When returning data that is to be used directly by JavaScript (#3
above), I always prefer JSON unless there are specific reasons to do
otherwise.  (JSON is already in a JavaScript-digestible format.)

I don't know the nature of your data or what you are trying to match,
but if it is something like

Form field:  'myentry'

And the returnData = {
 myentry: "this is a real user",
 film: "at eleven"
}

Then:

//may have to test this slightly differently,
//i.e., if (returnData.hasOwnProperty('myentry') {...}
if (typeof returnData.myentry !== 'undefined') {
 ...addClass('returnDataMatches');..
} else {
 ...addClass('noMatchMan');
}

Pyro



[jQuery] Re: Form Input Lookup

2007-08-30 Thread Phunky

Thanks for the replies i am actually using the autocomplete plugin for
my live search parts, but what im trying to create is just a lookup
which will not return any selection values but just addClass depending
what it finds.




[jQuery] Re: Form Input Lookup

2007-08-30 Thread duma


A Google link?  Come on, man.  Why even reply?

Phunky, there are autocomplete plugins.  You can find them on this page:
http://docs.jquery.com/Plugins

I've used and enhanced this one:
http://www.pengoworks.com/workshop/jquery/autocomplete.htm

My enhanced version includes the changes listed below.  Let me know if you'd
like to use it!

Updates to jquery.autocomplete.js

- You can have a question mark in your Url (will use a & instead, in that
case).
- Responses are expected to be Json.
- If there are more results than the number to be displayed, an ellipsis is
shown.
- Added the option displayField.  Whatever you specify for this option will
be the field that is displayed in the search results.  The default is "id".
- Added the option valueField.  Specify a string to use as the attribute to
use for the value of the field.  The default is "id".
- Added the option formFieldForValue.  Specify a string that matches the
field you want to use to store the value of the selected item.  For example,
"#MyHiddenField".
- Took out the caching for now, because it was causing problems and I don't
currently think it's a good idea.
- Added the option onUnknownValueEntered, which is an event called when the
user enters a value that isn't found.  The value entered is passed as a
parameter to the function you specify.
- The onItemSelect and onUnknownValueEntered callbacks pass the input field
to you as the second argument (the first being the li).

Bugfixes:
- Fixed a bug in moveSelect(step) that allowed an empty list (lis) to be
indexed into, even when the .length was 0.
- Fixed a bug which caused raw Html to be inserted into the autocompleted
field when tabbing when nothing was selected.
- In selectItem(li), I added a line that converts all of the Html entities
(e.g. &) to their textual counterparts (e.g. &).


Diego A. wrote:
> 
> 
> Start here:
> http://www.google.co.uk/search?q=jquery+autocomplete&sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGGL:2006-14,GGGL:en
> 
> 
> On Aug 30, 9:33 am, Phunky <[EMAIL PROTECTED]> wrote:
>> Hello, please do excuse my lack of knowledge with JS and JQuery but i
>> have attempted to avoid everything JS for many years as i just did not
>> like it.
>>
>> Although JQuery did make some simple aspects more manageable i still
>> try to avoid it... but sadly now i need to work with AJAX to make
>> aspects of a project more simple for its users :D
>>
>> I am currently trying to create a Username Look up function with
>> JQuery and i am trying to learn how to do this by hacking up the
>> jquery.autocomplete plugin i stumbled apon via pengoworks.com.
>>
>> But i feel im failing as i dont quite understand what is happening
>> with the script and this means im not really learning anything along
>> the way - which is not good for me in the long run as i would like to
>> finally get my head around JS ;)
>>
>> So if someone would like to step me in the right direction to what i
>> need to look at for creating a simple JQuery plugin/function that
>> would allow me to
>>
>> 1: Grab the value of a form input
>> 2: Grab results of a .php page via AJAX ( $.get()?? )
>> 3: Check through the AJAX results ( should i return the data as JSON?
>> or just | it? )
>> 4: If there is a match / likeness for what is in the form input
>> addClass('error') IF NOT addClass('accept')
>>
>> Quite simple really, but with my head my arse regarding JS im not 100%
>> sure what i should be looking to get through the points.
>>
>> If someone could just point me to the correct aspects of the API or
>> Help pages that would be great.
>>
>> Many thanks for any help and sorry if im just being a twittering
>> little JS noob :(
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Form-Input-Lookup-tf4353491s15494.html#a12406718
Sent from the JQuery mailing list archive at Nabble.com.



[jQuery] Re: Form Input Lookup

2007-08-30 Thread Diego A.

Start here:
http://www.google.co.uk/search?q=jquery+autocomplete&sourceid=navclient-ff&ie=UTF-8&rls=GGGL,GGGL:2006-14,GGGL:en


On Aug 30, 9:33 am, Phunky <[EMAIL PROTECTED]> wrote:
> Hello, please do excuse my lack of knowledge with JS and JQuery but i
> have attempted to avoid everything JS for many years as i just did not
> like it.
>
> Although JQuery did make some simple aspects more manageable i still
> try to avoid it... but sadly now i need to work with AJAX to make
> aspects of a project more simple for its users :D
>
> I am currently trying to create a Username Look up function with
> JQuery and i am trying to learn how to do this by hacking up the
> jquery.autocomplete plugin i stumbled apon via pengoworks.com.
>
> But i feel im failing as i dont quite understand what is happening
> with the script and this means im not really learning anything along
> the way - which is not good for me in the long run as i would like to
> finally get my head around JS ;)
>
> So if someone would like to step me in the right direction to what i
> need to look at for creating a simple JQuery plugin/function that
> would allow me to
>
> 1: Grab the value of a form input
> 2: Grab results of a .php page via AJAX ( $.get()?? )
> 3: Check through the AJAX results ( should i return the data as JSON?
> or just | it? )
> 4: If there is a match / likeness for what is in the form input
> addClass('error') IF NOT addClass('accept')
>
> Quite simple really, but with my head my arse regarding JS im not 100%
> sure what i should be looking to get through the points.
>
> If someone could just point me to the correct aspects of the API or
> Help pages that would be great.
>
> Many thanks for any help and sorry if im just being a twittering
> little JS noob :(