But for some reason, when the page is loaded, the dropdown does not display Eric Hunt as pre selected. Nor is anything for that matter. As it turns out, the above code works perfectly, thanks to the help of deceze and rosscj 's answers from below. The only reason it's not working for me is, I found ruby code that was overwriting the select elements.
The defaultSelected attribute is not settable, it's just for informational purposes:. The defaultSelected property returns the default value of the selected attribute. This property returns true if an option is selected by default, otherwise it returns false. You seem to have a lot of baggage and dependencies already and I can't tell you how to best integrate the selected option into your code without seeing more of it, but hopefully this helps.
Your code works for me. When does addSalespersonOption get called? There may be a problem with that call. Your select should look like this:. When does your options list get dynamically populated? Are you sure you are passing 'on' for the defSales value in your call to addSalespersonOption? Try changing that code to this:. Working example of my testing the error: Click Here More Details.
You need to call attr with two parameters, like this:. Your current code assigns the value "selected" to the variable defaultSelectedthen passes that value to the attr function, which will then return the value of the selected attribute.
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us. Log In Sign Up.
Autocomplete Widget | jQuery UI API Documentation
For some reason, I can't get this to work. My options list is populated dynamically using these scripts: Thanks for everyone's help on this, Cheers.
The if statement was my attempt to determine witch one of those options will display as the default selection in the select element. The defaultSelected attribute is not settable, it's just for informational purposes: I think you want: Without trying to fix your code, here's roughly how I would do it: Thanks deceze, But I cant get this to work.
I found another function that was part of this problem. So, I reworded the above question to include the function and hopefully it make more sense. Thanks for all your help so far.
You can use document. Here is a sample code. Check if you can use this type of approach: Hetal Vora 2, 2 20 Daniel McGrath 46 3. Your select should look like this: Try changing that code to this: I don't know how to find out when addSalespersonOption gets called. Thanks for the typo correction.
Ok, Yes, the alert reads: Hmmm, well it seems like that should work for you. I can't tell much more without seeing the rest of your code. I'll post a working example and see if you can tell any difference between it and your code. Thanks rosscj, I've never seen an editor like the one you use for the "Working example" before. Yes it is, just go to jsbin.
It's real helpful for little demos like the one I posted. Glad you found your problem! Your syntax is wrong. You need to call attr with two parameters, like this: SLaks k Thanks, But no luck.
Because I'm new and don't know what I'm doing! MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3.
Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.