Javascript, Razor and Escape characters. Like apostrophe

I would write your foreach like this: @foreach (var s in ViewBag.Sessions) { <text> { title: ‘@HttpUtility.JavaScriptStringEncode(s.Name)’, start: new Date(@s.Starts.Year, @s.Starts.Month-1, @s.Starts.Day), end: new Date(@s.Ends.Year, @s.Ends.Month-1, @s.Ends.Day) }, </text> } HttpUtility.JavaScriptStringEncode to escape quotes and html markup. <text> is nicer for multiline output.

Implementing jquery UI autocomplete to show suggestions when you type “@”

You can do this by providing a function to the source option of autocomplete: var availableTags = [ /* Snip */]; function split(val) { return val.split(/@\s*/); } function extractLast(term) { return split(term).pop(); } $(“#tags”) // don’t navigate away from the field on tab when selecting an item .bind(“keydown”, function(event) { if (event.keyCode === $.ui.keyCode.TAB && … Read more

How to detect an audio has finished playing in a web page?

If you are using the html5 audio tag, there is the “onended” event handler. I donĀ“t know if the browsers support it yet. Something like: <audio src=”https://stackoverflow.com/questions/4619917/xpto.mp3″ onended=”DoSomething();”></audio> In the last case you can use a swf that can play the sound, and alert your javascript when it reaches the end.

jQuery datepicker- 2 inputs/textboxes and restricting range

Many thanks for your help Ben, I have built upon your posts and have come up with this. It is now complete and works brilliantly! Here’s a Working Demo. Add /edit to the URL to see the code Complete Code below- $(function () { $(‘#txtStartDate, #txtEndDate’).datepicker({ showOn: “both”, beforeShow: customRange, dateFormat: “dd M yy”, firstDay: … Read more

jQuery file upload: Is it possible to trigger upload with a submit button?

if you have the button <button id=”up_btn”>Upload</button> You can try with $(‘#fileupload’).fileupload({ dataType: ‘json’, add: function (e, data) { $(“#up_btn”).off(‘click’).on(‘click’, function () { data.submit(); }); }, }); EDIT: according to comments a better answer considere off to avoid duplicated requests. (also work unbind, I do not check if is bind and unbind but jquery team … Read more