Event listener not working

You must Login before you can answer or comment on any questions.

Hi my button event listener is not working.It was working till yesterday correctly but now it is not working var GlobalVar=new Array(); GlobalaVar=["PHP Web Developer","Drupal Developer"]; var win5 = Titanium.UI.createWindow({ title : 'Tab 5', backgroundColor : '#fff' });

     var searchbyjob = Titanium.UI.createTextField({
hintText : 'Search By Job',
top : 25,
borderWidth : 0,
width : 350,
left : 60,
height : 60,
font : {
    fontSize : 14,
    fontColor : '#262626',
    fontFamily : 'Helvetica'
},
autoCorrect : false,
//autocapitalization : Titanium.UI.TEXT_AUTOCAPITALIZATION_ALL,
//  keyboardType:Titanium.UI.KEYBOARD_NUMBER_PAD
       });
          win5.add(searchbyjob);
        var searchbycompany = Titanium.UI.createTextField({
hintText : 'Search By Company',
top : 100,
borderWidth : 0,
width : 350,
left : 60,
height : 60,
font : {
    fontSize : 14,
    fontColor : '#262626',
    fontFamily : 'Helvetica'
},
autoCorrect : false,
autocapitalization : Titanium.UI.TEXT_AUTOCAPITALIZATION_ALL
      });
          win5.add(searchbycompany);
  // Create the search button from our search.png image
    var btnSearchcompany = Titanium.UI.createButton({
backgroundImage : 'images/search.png',
top : 112,
width : 80,
height : 30,
right : 75,
borderRadius : 3
      });
      win5.add(btnSearchcompany);
      / / Create the search button from our search.png image
     var btnSearchjob = Titanium.UI.createButton({
backgroundImage : 'images/search.png',
top : 37,
width : 80,
height : 30,
right : 75,
borderRadius : 3
     });
      win5.add(btnSearchjob);
       var tableView2 = Titanium.UI.createTableView();
      win5.add(tableView2);

      btnSearchjob.addEventListener('click', function(e) {
      searchyql();


      });
       function searchyql(){
var n = 0;
var count = 0;
var a = GlobalVar.length;
for (var i = 0; i < GlobalVar.length; i++) {
        alert(GlobalVar[i]);
    n++;

    if (GlobalVar[i] == searchbyjob.value) {
        btnSearchjob.hide();
        btnSearchcompany.hide();
        searchbyjob.hide();
        searchbycompany.hide();
        count++;
        var Row = [];
        Titanium.Yahoo.yql('select * from html where url="http://afghanskills.com/all-jobs.php"  and xpath="//tbody/tr[' + n + ']/td/font"', function(e) {
            var results = e.data.font;

            for (var i = 0; i < results.length; i++) {
                var rss = results[i];
                var rssRow = Titanium.UI.createTableViewRow({
                    top : 200,
                    height : 45,
                    className : 'rssrow'

                });
                var titleLabel = Titanium.UI.createLabel({
                    text : rss.content,
                    font : {
                        fontSize : 16,
                        fontWeight : 'bold'
                    },
                    width : 'auto',
                    top : 5,
                    left : 40,
                    height : 16
                });

                rssRow.add(titleLabel);

                Row.push(rssRow);
            };

            tableView2.setData(Row);

        });
    } else if (n == a - 1 && count == 0) {
        alert("Your Job IS NOT FOUND");
    }
}

} win5.open();

— asked 8 months ago by Muhammad Wahhab Mirza
4 Comments
  • What TiSDK version are you using, and what platform versions are you targeting? I tried your code, and it just renders a table view and nothing else. What is it actually supposed to do/show?

    — commented 8 months ago by Daniel Sefton

  • For anyone else trying to reproduce, here's formatted copy+pastable code:

    var GlobalVar = new Array();
    GlobalaVar = ["PHP Web Developer", "Drupal Developer"];
    var win5 = Titanium.UI.createWindow({
        title : 'Tab 5',
        backgroundColor : '#fff'
    });
     
    var searchbyjob = Titanium.UI.createTextField({
        hintText : 'Search By Job',
        top : 25,
        borderWidth : 0,
        width : 350,
        left : 60,
        height : 60,
        font : {
            fontSize : 14,
            fontColor : '#262626',
            fontFamily : 'Helvetica'
        },
        autoCorrect : false,
        //autocapitalization : Titanium.UI.TEXT_AUTOCAPITALIZATION_ALL,
        //  keyboardType:Titanium.UI.KEYBOARD_NUMBER_PAD
    });
    win5.add(searchbyjob);
    var searchbycompany = Titanium.UI.createTextField({
        hintText : 'Search By Company',
        top : 100,
        borderWidth : 0,
        width : 350,
        left : 60,
        height : 60,
        font : {
            fontSize : 14,
            fontColor : '#262626',
            fontFamily : 'Helvetica'
        },
        autoCorrect : false,
        autocapitalization : Titanium.UI.TEXT_AUTOCAPITALIZATION_ALL
    });
    win5.add(searchbycompany);
    // Create the search button from our search.png image
    var btnSearchcompany = Titanium.UI.createButton({
        backgroundImage : 'images/search.png',
        top : 112,
        width : 80,
        height : 30,
        right : 75,
        borderRadius : 3
    });
    win5.add(btnSearchcompany);
    // Create the search button from our search.png image
    var btnSearchjob = Titanium.UI.createButton({
        backgroundImage : 'images/search.png',
        top : 37,
        width : 80,
        height : 30,
        right : 75,
        borderRadius : 3
    });
    win5.add(btnSearchjob);
    var tableView2 = Titanium.UI.createTableView();
    win5.add(tableView2);
     
    btnSearchjob.addEventListener('click', function(e) {
        searchyql();
     
    });
    function searchyql() {
        var n = 0;
        var count = 0;
        var a = GlobalVar.length;
        for (var i = 0; i < GlobalVar.length; i++) {
            alert(GlobalVar[i]);
            n++;
     
            if (GlobalVar[i] == searchbyjob.value) {
                btnSearchjob.hide();
                btnSearchcompany.hide();
                searchbyjob.hide();
                searchbycompany.hide();
                count++;
                var Row = [];
                Titanium.Yahoo.yql('select * from html where url="http://afghanskills.com/all-jobs.php"  and xpath="//tbody/tr[' + n + ']/td/font"', function(e) {
                    var results = e.data.font;
     
                    for (var i = 0; i < results.length; i++) {
                        var rss = results[i];
                        var rssRow = Titanium.UI.createTableViewRow({
                            top : 200,
                            height : 45,
                            className : 'rssrow'
     
                        });
                        var titleLabel = Titanium.UI.createLabel({
                            text : rss.content,
                            font : {
                                fontSize : 16,
                                fontWeight : 'bold'
                            },
                            width : 'auto',
                            top : 5,
                            left : 40,
                            height : 16
                        });
     
                        rssRow.add(titleLabel);
     
                        Row.push(rssRow);
                    };
     
                    tableView2.setData(Row);
     
                });
            } else if (n == a - 1 && count == 0) {
                alert("Your Job IS NOT FOUND");
            }
        }
    }
     
    win5.open();

    — commented 8 months ago by Daniel Sefton

  • I have debugged it when i click on job button it does not enter in the function searchyql() body.

    — commented 8 months ago by Muhammad Wahhab Mirza

  • Show 1 more comment

1 Answer

There are two button on it and which one is not working...

var btnSearchcompany = Titanium.UI.createButton({   //button 1 does not have any event listener
backgroundImage : 'images/search.png',
top : 112,
width : 80,
height : 30,
right : 75,
borderRadius : 3
      });
      win5.add(btnSearchcompany);
      / / Create the search button from our search.png image
     var btnSearchjob = Titanium.UI.createButton({ //button 2 has event listener.
backgroundImage : 'images/search.png',
top : 37,
width : 80,
height : 30,
right : 75,
borderRadius : 3
     });
for button 2 click event.. put the log message on click and put that console message here... and also confirm that its tapped properly.. there is no hidden view also.

— answered 8 months ago by Ashish Nigam
answer permalink
8 Comments
  • I have made a listener of btn listener for 2nd and it is not working.When i click on it it does not do anything

    — commented 8 months ago by Muhammad Wahhab Mirza

  • i suggested you to do something.. make sure those things.. and you are calling searchyql(); from click event... may be there is any problem in searchyql(); function.. so try putting some console log or alert there on click before function call.

    — commented 8 months ago by Ashish Nigam

  • Hi I have now shown only alert but it is still not working function searchyql(){ alert("I am a good person"); }

    — commented 8 months ago by Muhammad Wahhab Mirza

  • Show 5 more comments

Your Answer

Think you can help? Login to answer this question!