-
Feb 8th, 2012, 08:49 AM
#1
Thread Starter
Hyperactive Member
Statement seems to be ignored unless something exec before it.
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.
Code:
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.
-
Feb 8th, 2012, 08:59 AM
#2
Re: Statement seems to be ignored unless something exec before it.
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:
Code:
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??
-
Feb 8th, 2012, 09:23 AM
#3
Thread Starter
Hyperactive Member
Re: Statement seems to be ignored unless something exec before it.
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.
-
Feb 8th, 2012, 12:47 PM
#4
Re: Statement seems to be ignored unless something exec before it.
This is needlessly convoluted:
Code:
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).
-
Feb 8th, 2012, 01:01 PM
#5
Re: Statement seems to be ignored unless something exec before it.
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".
-
Feb 8th, 2012, 02:40 PM
#6
Thread Starter
Hyperactive Member
Re: Statement seems to be ignored unless something exec before it.
Thanks guys. Will try again tomorrow, strip things down and post some more I cannot solve it.
Thanks a lot.
-
Feb 10th, 2012, 06:15 PM
#7
Re: Statement seems to be ignored unless something exec before it.
Did you get a resolution to this??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|