Click here to Skip to main content
15,915,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
<input id="CHAMPARAN_EAST" name="CHAMPARAN EAST" onclick="SearchDistict('CHAMPARAN EAST');" type="checkbox" value="34">

function SearchDistict(obj) 
{
        debugger;
        if (obj.checked) 
         {
          districtCollection.push(obj.value);
         }
        else {
            districtCollection.pop(obj.value);
            //districtCollection.splice($.inArray(obj.value, districtCollection),1);

        }
        var postData = preparingSearch();
        debugger;
        postData.StateList = '';
        postData.DistrictList = districtCollection;
        SearchEngine();
        //CallSearchBorrower(postData);
    }

when we call SearchDistict('CHAMPARAN EAST') its work but it not invoke if statement
Posted
Updated 19-Jul-15 22:23pm
v2

1 solution

(You are passing control name as string and within the function, using it as a control. [string != control])


Here is the fix:
1. Rename your checkbox name attribute same as id.
2. Pass control name as parameter.

XML
<input id="CHAMPARAN_EAST" name="CHAMPARAN_EAST" onclick="SearchDistict('CHAMPARAN_EAST');" type="checkbox" value="34">

function SearchDistict(obj)
{
var ctrl = $("#"+ obj);
 
Share this answer
 
v2
Comments
Thanks7872 20-Jul-15 5:14am    
No. This is not a good practice. There are chances of errors. SearchDistict(this) should be used.
Sreekanth Mothukuru 20-Jul-15 6:56am    
Yes Rohan. this as function parameter is always the right approach to pick the current object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900