2

Here is the script i wrote to read each character from a textbox and checking whether that character exists in a array but this isn't working correctly as i'm getting a -1 for any character i enter into the textbox despite of whether its there or not in the array i'm searching that value. Can anyone please help

$(document).ready(function()
{
    var arr1;
    var arr2= $("#myValue").val().split("");

    $("#TextBox1").keyup(function ()
    { 
        arr1 = $("#TextBox1").val().split("");
    });

    $("#btn").click(function ()
    { 
        jQuery.each(arr1, function(i, val)
        {
            $("#xyz").append(this + "<br/>");
            $("#xyz").append(jQuery.inArray(this, arr2)+"<br/>");
        });
    });
});
Josh Mein
  • 28,107
  • 15
  • 76
  • 87

2 Answers2

0

Since this is ASP.NET, have you double checked that #TextBox1 is the actual final element ID? It might end up be something like #ctl102_TextBox1

rusty
  • 2,771
  • 1
  • 24
  • 23
  • yes i did the id is correct, in fact if i change the code to display the items what i'm searching for, its display the correct items. Thanks..! – Tharindu Liyanage May 23 '11 at 18:48
0

the problem is in this line:

$("#xyz").append(jQuery.inArray(this, arr2)+"<br/>");

change it to:

$("#xyz").append(jQuery.inArray(this.toString(), arr2)+"<br/>");

because this is an object

roberkules
  • 6,557
  • 2
  • 44
  • 52