How to set the ‘selected option’ of a select dropdown list with jquery

Try this : $(‘select[name^=”salesrep”] option[value=”Bruce Jones”]’).attr(“selected”,”selected”); Just replace option[value=”Bruce Jones”] by option[value=result[0]] And before selecting a new option, you might want to “unselect” the previous : $(‘select[name^=”salesrep”] option:selected’).attr(“selected”,null); You may want to read this too : jQuery get specific option tag text Edit: Using jQuery Mobile, this link may provide a good solution : jquery … Read more

UITableViewCell Selected Background Color on Multiple Selection

All the above answers are fine but a bit to complex to my liking. The simplest way to do it is to put some code in the cellForRowAtIndexPath. That way you never have to worry about changing the color when the cell is deselected. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let … Read more

dropdownlist set selected value in MVC3 Razor

You should use view models and forget about ViewBag Think of it as if it didn’t exist. You will see how easier things will become. So define a view model: public class MyViewModel { public int SelectedCategoryId { get; set; } public IEnumerable<SelectListItem> Categories { get; set; } } and then populate this view model … Read more

Keeping a UIButton selected after a touch

How are you setting the images for the different UIControlStates on the button? Are you setting a background image for UIControlStateHighlighted as well as UIControlStateSelected? UIImage *someImage = [UIImage imageNamed:@”SomeResource.png”]; [button setBackgroundImage:someImage forState:UIControlStateHighlighted]; [button setBackgroundImage:someImage forState:UIControlStateSelected]; If you’re setting the selected state on the button touch down event rather than touch up inside, your button … Read more