Javascript
Javascript
-
open new window popup using javascript
<script> function popupW() { window.open(‘http://google.com’,’banco’,’toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no’); return true; } popupW(); </script> Continue reading
-
Increment date by any number using js
This is the function to do so: function increment_date(date,increment) { var dateString = date; var myDate = new Date(dateString); myDate.setDate(myDate.getDate() + increment); var y = myDate.getFullYear(), m = myDate.getMonth() + 1, // january is month 0 in javascript d = myDate.getDate(); var pad = function(val) { var str = val.toString(); return (str.length < 2) ?… Continue reading
-
Validate image with dimension
HTML CODE: <input type=”file” required=”required” class=”file” id=”category_image” error=”error” name=”category_image”> JAVA SCRIPT: $(‘#CategoryEditForm’).validate({ errorElement: ‘div’, errorClass: ‘help-block’, focusInvalid: false, rules: { “category_image”: { extension: “png|jpg|gif|jpeg|bmp” } }, messages: { “category_image”: { extension: “This field can accept images only!” } }, invalidHandler: function (event, validator) { //display error alert on form submit $(‘.alert-danger’, $(‘.login-form’)).show(); }, highlight: function… Continue reading
-
equal height elements
function equalHeight(group) { var tallest = 0; group.each(function() { var thisHeight = $(this).height(); if(thisHeight > tallest) { tallest = thisHeight; } }); group.height(tallest); } equalHeight($(“.commonclass”)); Continue reading
-
Restrict space at first position in textbox using jquery/javascript
$(“input”).on(“keypress”, function(e) { if (e.which === 32 && !this.value.length) e.preventDefault(); }); Continue reading
-
html page form enlarge in mobile device
$(‘input[type=search]’).on(‘focus’, function(){ // replace CSS font-size with 16px to disable auto zoom on iOS $(this).data(‘fontSize’, $(this).css(‘font-size’)).css(‘font-size’, ’16px’); }).on(‘blur’, function(){ // put back the CSS font-size $(this).css(‘font-size’, $(this).data(‘fontSize’)); }); Continue reading
-
Get geolocation contry,city,region_name using js
function getcurrentlocation() { theUrl=”http://freegeoip.net/json/”+myIP(); xmlhttp.open(‘get’, theUrl, true); xmlhttp.onreadystatechange = ReplyUrl; xmlhttp.send(null); } function ReplyUrl() { if(xmlhttp.readyState == 4) { if(xmlhttp.responseText != “”) { var response = xmlhttp.responseText; var parsedJSON = eval(‘(‘+response+’)’); var location; location = document.getElementById(‘location’).value; console.log(parsedJSON.city+”, “+parsedJSON.region_name+”, “+parsedJSON.country_name); if(parsedJSON.city) location =location+”,”+parsedJSON.city; if(parsedJSON.region_name) location =location+”,”+parsedJSON.region_name; if(parsedJSON.country_name) location =location+”,”+parsedJSON.country_name; console.log(location); document.getElementById(‘location’).value = location; } else {… Continue reading
-
Use jQuery to get the width of an element in percent
Use jQuery to get the width of an element in percent or pixels, based on what the developer specified with CSS var width = $(‘#someElt’).width(); var parentWidth = $(‘#someElt’).offsetParent().width(); var percent = 100*width/parentWidth; or you can use var width = ( 100 * parseFloat($(‘.largeField’).css(‘width’)) / parseFloat($(‘.largeField’).parent().css(‘width’)) ) + ‘%’ Continue reading
-
Validation for file extensions
function CheckValidFile(val,name,extValue,title) { var a = val.substring(val.lastIndexOf(‘.’) + 1).toLowerCase(); var ext=document.getElementById(extValue).value; var ext=ext.split(‘,’); var len=ext.length; for(i=0;i { if(a == ext[i]) { return true; } } alert(‘The extension ‘ + a.toUpperCase() + ‘ is not valid. Please Upload only ‘+title+’ Files.’); ClearBrowseContent(name); document.getElementById(name).value=”; return false; } function ClearBrowseContent(control) { var browse=document.getElementById(control); var newbrowse= browse.cloneNode(false); browse.parentNode.replaceChild(newbrowse ,browse);… Continue reading
-
Open URL in new window using javascript
function pollwin(url,w, h) { pollwindow=window.open(url,’pollwindow’,’top=0,left=0,status=no,toolbars=no,scrollbars=no,width=’+w+’,height=’+h+’,maximize=no,resizable’); pollwindow.focus(); } Continue reading
About Me
A seasoned web developer with over 14 years of experience, has honed a craft across a variety of frameworks and platforms.