How to get index of checkbox on the base of checkbox value?

Before fifteen days, in my task I required to get index of checkbox from checkbox array on the base of checkbox value.
There were about 70 to 80 checkboxes in an array.

And I need an index of particular checkbox when I give value of that checkbox.

At that time I found a solution to use “Array.indexOf(searchStr[, startIndex])” method of javascript.

But it was not a proper solution, because javascript “Array.indexOf(searchStr[, startIndex])” method is not supported in Internet Explorer and older browsers.

So I used following javascript function to get index of particular checkbox.

function get_index_by_value(checkbox_array, value_to_search)
	for(var i=0; i< checkbox_array.length; i++)
    	if(checkbox_array [i].value == value_to_search)
     		return i;

Above function have two arguments.

First one is checkbox_array and second is value_to_search.

By calling get_index_by_value function with correct arguments, it returns the index of checkbox where the given value has been found.

Speak Your Mind

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: