0

I have the following bit of Javascript:

function select(id, evt) { 
        var e = (typeof evt != 'undefined') ? evt : event;
        e.cancelBubble = true;
        alert('err');
        var $toggler = $("#building"+id);     
        
        if(!$toggler.is(':checked')){
            $toggler.attr('checked', true);
            $("#row"+id).removeClass("selectRow");
            $("#row"+id).addClass("selectRow");            
        } 
    }

I have the following <HTML> block

<td>
   <select onchange="select(2, event);" name="prefferedAgent396" class="input-small">
       <option value="0">Choose...</option>
       <option value="1" selected=""> Senthil </option>                                    
       <option value="3"> Sunmeet </option>                                    
       <option value="4"> Doesnot Speak English </option>                                    
       <option value="5"> Marcus Fava </option>                                    
   </select> 
</td>
<td>
   <input type="text" onchange="select(2, event);" class="input-mini" id="initial396" name="initial396" value="">
</td>

Now the problem is the onchange event triggers the select(2, event) for the select control but not the input control. When i tried an alert box where I call select() it worked but its not simply calling the select(). I have tried onKeyUp but it gave a strange behavior of replacing the text as I type. What am I doing wrong here?

2
  • 1
    I'd move that alert to the top of your select function, in case there's something in your cancel bubble code that's breaking. Have you looked at what the console is reporting when you fire this event? (eg in Chrome dev tools or Firbebug etc) Commented Aug 29, 2012 at 0:08
  • No errors nothing.. I have checked the console.. and i removed the cancel bubble code as well.. No luck!! Commented Aug 29, 2012 at 0:31

1 Answer 1

1

That's very strange. If you rename the function from select to, say select_, it will work. But since you're already using jQuery, you can use the following instead of using the inline change handlers:

$("#prefferedAgent396,#initial396").change(function (e) {
   select(2, e);
});

Here's a DEMO.

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

1 Comment

I faced with similar problems before bu i wan't thinking this time.. thanks!!

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.