# Other Languages > jQuery >  Statement seems to be ignored unless something exec before it.

## Krokonoster

Hi,
Got 3 cascading dropdowns (Clients -> Departments -> Teams) and loading their data using jquery ajax calls.  (there are a lot to the rest of the form though, though not related to this problem )

Since I am clearing dropdowns and hiding elements all over, I wanted to created a function  that can be called any time that will do that in one  place).  however I soon got stuck.

The following code works perfectly, until I one uncomment the alert.  From then, the next line seems to just get ignored.



```
function SetControlsVisibility() {
    var clientId = $("select#ClientId > option:selected").attr("value");
    if (clientId == '' || clientId == undefined) {
        alert("abc");
        $('#DepartmentId').empty().prev().text("");   // ain't do it if no alert....
        .....
```

got a strong feeling of devaju here, but just cannot remember where I ran into this issue before though.

----------


## szlamany

I've also experienced issues like this - not sure how I cleared it up.

Do you have some kind of missing ; somewhere?  I save backup copies of my JS code so I can do a quick WINDIF when something like this happens.

How about changing your code to this:



```
        var wesDept = $('#DepartmentId');
        wesDept.empty().prev().text("");   // ain't do it if no alert....
```

Does that run?

Can you break/step at that spot with FIREBUG??

----------


## Krokonoster

Hi,
Nope, that seems not to work.

Unfortunately (NOTE: I quit from this and just working out my notice) the environment I work in, you log into a remote machine, without internet, with vs installed on it.  so cannot install firefox, let alone firebug.  Have this been on my own machine i probably would sort it out in a few.  But crippled like this.

----------


## SambaNeko

This is needlessly convoluted:


```
var clientId = $("select#ClientId > option:selected").attr("value");
//equivalent to:
var clientId = $("#ClientId").val();
```

Can't really tell what the problem is; was unable to reproduce it with an assumptive setup.  It might help if you can provide more context (the markup and any other related scripting).

----------


## szlamany

Quick note on what SambaNeko posted

Using a SELECTOR of an HTML ID is one of the fastest selectors - jQuery is optimized to locate that DOM element - always DESCEND from an #ID

http://www.artzstudio.com/2009/04/jq...ormance-rules/

And note that my wesDept - although not meaningful in this context - is really important to use.  Always cache the selection if it's going to be used repeatedly.  To me wes stands for "wrapped element set".

----------


## Krokonoster

Thanks guys.  Will try again tomorrow, strip things down and post some more I cannot solve it.
Thanks a lot.

----------


## szlamany

Did you get a resolution to this??

----------

