2

Hope I provided a clear title.

I am creating an array comprised of all options, trimming whitespace, and storing. (correct me if im wrong in my process). On input change, if option array returns false, clear the next field, else, store the unique new value and place in next field.

If array contains:

blue
black
brown

and I search for BLUE or Blue or BLue...etc, the result returns false. I guess im asking for caseInsensitive logic, but not sure how I can incorporate.

Ive done this all on trial and error so please feel free to refine if your time allots. Also, this needs to be within spec of jquery 1.3

http://jsfiddle.net/arkjoseph/dRpmq/2/

thank you for assistance.

1

2 Answers 2

3

Since it looks like you have control of the values (and are making them lowercase), you can do a pretty simple change from:

if (($.inArray((this.value), option) > 0)

to

if (($.inArray((this.value.toLowerCase()), option) > 0)

Demo at http://jsfiddle.net/dRpmq/3/

Sign up to request clarification or add additional context in comments.

2 Comments

if (($.inArray((this.value), option) > -1), no? index can be zero??
Old post, but yes, in theory. In this particular case, he has a dummy value at index 0 which I imagine he'd want to ignore in the search.
-1

From Case insensitive search in array JavaScript provide a Method indexOf() which is used to search object from array but this is case sensitive.

Jquery provide a method jQuery.inArray() To search object in array but this is case sensitive also i.e “a” is not equal to “A”. So we have to make our own function, Following is small javascript function which return index of object if found in array otherwise return -1 and this is case insensitive method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.