Converting json results to a date

 

Solution1:

var date = new Date(parseInt(jsonDate.substr(6)));

 

Solution2:

var x = [{
    "id": 1,
    "start": "\/Date(1238540400000)\/"
}, {
    "id": 2,
    "start": "\/Date(1238626800000)\/"
}];

var myDate = new Date(x[0].start.match(/\d+/)[0] * 1);


 

Source: https://stackoverflow.com/questions/206384/how-do-i-format-a-microsoft-json-date

https://stackoverflow.com/questions/1244094/converting-json-results-to-a-date

 

 

Advertisements

Add maxlength on textArea using jQuery

The Low Down

The maxlength attribute limits the number of characters that an <input> or<textarea> can accept. The maxlength attribute on textarea is new in HTML5.

  • Works for GUI-less inputs like text, email, url, search, tel and password.
  • Upon data entry, browsers will not permit the user to enter more than the characters defined by the value of the maxlength attribute: cutting off the text as-you-type and truncating pasted text. This can lead to bad user experience.
  • maxlength does not limit placeholder length.
  • If a preset value is included with a value that has more characters than the allowed length, a validation error will not be thrown. However, if that preset value is edited, yet is still longer than the allowed length, the element will become invalid, matching the :invalid pseudoclass selector, and will be prevented from being submitted in both Opera and IE10+, which both display the tooLong validity error message.
  • IE 9 reported support on both inputs and textareas but only works on inputs.

Source: https://www.wufoo.com/html5/attributes/03-maxlength.html

 

HTML 5
The textArea “maxlength” attribute is supported in HTML 5, the problem is not all browsers support HTML 5, especially, the old IE.

 

jQuery Example

A jQuery example to implement the “maxlength” effect on a textarea field.

<html>
<head>
<script language="javascript" type="text/javascript"
	src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script language="javascript" type="text/javascript">

    $(document).ready( function () {

	maxLength = $("textarea#comment").attr("maxlength");
        $("textarea#comment").after("
" + maxLength + " remaining
"
); $("textarea#comment").bind("keyup change", function(){checkMaxLength(this.id, maxLength); } ) }); function checkMaxLength(textareaID, maxLength){ currentLengthInTextarea = $("#"+textareaID).val().length; $(remainingLengthTempId).text(parseInt(maxLength) - parseInt(currentLengthInTextarea)); if (currentLengthInTextarea > (maxLength)) { // Trim the field current length over the maxlength. $("textarea#comment").val($("textarea#comment").val().slice(0, maxLength)); $(remainingLengthTempId).text(0); } }
</script> </head> <body> <h1>TextArea maxlength with jQuery</h1> <textarea id="comment" maxlength="10" rows="10" cols="60" ></textarea> </body> </html>

 

Source: http://www.mkyong.com/jquery/add-maxlength-on-textarea-using-jquery/

 

 

 

 

 

Asc/Desc tooltip on sorting columns?

 

$(‘th’).each(function(){
if (($(this).hasClass(‘sorting’)) || ($(this).hasClass(‘sorting_desc’))) {
$(this).attr({title: ‘Sort Ascending’});
} else {
$(this).attr({title: ‘Sort Descending’});
}
});

 

Source: https://datatables.net/forums/discussion/718/asc-desc-tooltip-on-sorting-columns

 

Button type “button” vs. “submit”

type
The type of the button. Possible values are:

  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element’s events, which are triggered when the events occur.

 

https://stackoverflow.com/questions/7117639/input-type-submit-vs-button-tag-are-they-interchangeable

https://stackoverflow.com/questions/37736056/button-type-button-vs-submit

https://stackoverflow.com/questions/290215/difference-between-input-type-button-and-input-type-submit

 

 

jquery detect textbox value change NOT based on user input

http://javascript.qahowto.com/jquery-detect-textbox-value-change-NOT-based-on-user-input-javascript-jquery-f4dfd4

https://stackoverflow.com/questions/16048084/jquery-detect-textbox-value-change-not-based-on-user-input

var $myText = $(“#myText”); $myText.data(“value”, $myText.val()); setInterval(function() { var data = $myText.data(“value”), val = $myText.val(); if (data !== val) { $myText.data(“value”, val); alert(“changed”); } }, 100);