Skip to main content

Posts

Showing posts with the label Jquery

Render bundle script after page load using Javascript

get bundle url and set in script tag in Head after page load  window.onload = function () {             var LayoutJsBundleUrl = ('@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/LayoutJs")');             var script = document.createElement("script");             script.src = LayoutJsBundleUrl;             script.type = "text/javascript";             document.getElementsByTagName("head")[0].appendChild(script);         } Also get bundle url from Scripts.Url("~/bundles/LoginJs")

How to Get Dropdown's Selected Item's property in Kendo UI?

Kendo Dropdown: getting the selected item You could use the   dataItem   method of the ComboBox/Dropdown to get the model for the selected item. As a side note, the context of the event handler is the ComboBox and it is accessible via   this . E.g. function   change(e) {      var   text =   this .text();      var   value =   this .value();      var   object =   this .dataItem( this .select()); } I hope that this information was helpful for you. I wish you a great day! and another way is : var ddl = $ ( "#ddl" ). data ( "kendoDropDownList" ). dataItem ( $ ( "#ddl" ). data ( "kendoDropDownList" ). select ()). FieldName ; //FieldName is the text field of DataSource --- .DataTextField("FieldName") Ref :  http://www.telerik.com/forums/getting-the-selected-item Ref : http://stackoverflow.com/questions/21600895/how-to-get-dropdowns-selected-items-tex...

Check if Popup Window Closed

Sometimes you will want to use a popup window for an antiquated system and need to maintain a reference to the popup window so that when the popup loses focus you can bring it back in focus with a click of a button. The following script will allow you to do that. In brief, the script opens a window when a button is clicked, if it loses focus you just need to click the button again to get it back. The script also deals with the fact that the user may close their browser window, navigate away from the main page or refresh the current browser window. Enjoy! <html> <head> <title></title> <script type="text/javascript" src=" http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "> </script> </head> <body> <button id="button">Click Me!</button> <script type="text/javascript"> var win; $(window).load(function() { $('#button').click(function(){ openPo...

Smooth Scrolling To Internal Links With jQuery

jQuery allows you change the way you interact with your website with very little code. jQuery has an animate function which allows you to animate anything that jQuery does, including scrolling. Animate scrolling creates a better effect to the visitor than to just job to a place on the page. There are many websites that will use internal links to jump to different parts of the page this is done by using a # and then the element id in the anchor tag. < a href = " #services " > Jump to services </ a > < div id = " services " > </ div > Doing the above creates a link that will move the page to the services div when you click it. But it jumps to this position and if it's far down the page it's not the nicest effect to the visitor. It's better if you can actually scroll to this position to help the visitors see where this is positioned. In jQuery if you set an animation on the scroll event then it creates a scrolling...

Count characters/sms using jQuery

HTML: <textarea name = "message" value = "" id = "message" ></textarea> <p> <span id = "remaining" > 160 characters remaining </span> <span id = "messages" > 1 message(s) </span> </p> jQuery: $ ( document ). ready ( function (){ var $remaining = $ ( '#remaining' ), $messages = $remaining . next (); $ ( '#message' ). keyup ( function (){ var chars = this . value . length , messages = Math . ceil ( chars / 160 ), remaining = messages * 160 - ( chars % ( messages * 160 ) || messages * 160 ); $remaining . text ( remaining + ' characters remaining' ); $messages . text ( messages + ' message(s)' ); }); }); See jsFiddle example. Ref:  http://stackoverflow.com/questions/4705185/count-characters-sms-using-jquery

MVC: How to display validation messages with javascript alert window?

For the unobtrusive client validation you could subscribe to the  showErrors  callback and display the errors the way you want ( alert  in your case): ( function ( $ ) { $ . validator . setDefaults ({ onsubmit : true , onkeyup : false , onfocusout : false , showErrors : function ( errorMap , errorList ) { if ( errorList . length > 0 ) { var errors = errorList . map ( function ( element ) { return element . message ; }). join ( '\r\n' ); alert ( errors ); } } }); })( jQuery ); In order to display server side errors with  alert  on the client you shouldn't be using the  @Html.ValidationSummary( true )  helper because this helper outputs the errors directly in the view and you said that you don't have enough place. So you could emit javascript dynamically when there are errors and...

Return value from function with an Ajax call [duplicate] (Jquery : call ajax and return value in function)

Jquery Code <script src="jscripts/jquery-1.7.2.min.js" type="text/javascript"></script>     <script type="text/javascript">         test();         function test() {             alert('Call Ajax Function');             myFunction(function (d) {                 //processing the data                 alert("Return Datetime from Ajax Request. The Datetime is : " + d);             });             alert('Done');         }         function myFunction(callba...

JQuery Event for user pressing enter in a textbox?

$ . fn . pressEnter = function ( fn ) { return this . each ( function () { $ ( this ). bind ( 'enterPress' , fn ); $ ( this ). keyup ( function ( e ){ if ( e . keyCode == 13 ) { $ ( this ). trigger ( "enterPress" ); } }) }); }; //use it: $ ( 'textarea' ). pressEnter ( function (){ alert ( 'here' )})   Ref : http://stackoverflow.com/questions/6524288/jquery-event-for-user-pressing-enter-in-a-textbox