Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Wednesday, May 9, 2012

Integer validation in JavaScript

function isInteger(val) {
    var intRegEx = /\D/g;
    return (!intRegEx.test(val));
}

Tuesday, March 20, 2012

Request the parent window to open a URL from an iframe with different domains

Sometime we are developing something within an iframe, but we want the parent window to refresh or open a URL. The code to use is:
top.location.href = URL;

Monday, November 7, 2011

JavaScript: waiting 5 seconds and auto redirects

<div>Redirect to the home page in <span id="countdown">5</span> secondes...</div>
<script type="text/javascript">
function countDown(){
 var count = document.getElementById('countdown').innerHTML-1;
 document.getElementById('countdown').innerHTML = count;
 if (count<=0) {
  location.href = "http://networkplot.tk";
 }
 else {
  t=setTimeout("countDown()",1000);
 }
}
countDown();
</script>

Sunday, November 6, 2011

JavaScript check whether a string contains only characters and numbers

function checknum(value) {
    var Regx = /^[A-Za-z0-9]*$/;
    if (Regx.test(value)) {
        return true;
    }
    else {
        return false;
    }
}

Thursday, August 18, 2011

Frequently used javascripts

Create a download button with inline Javascript
<button onclick="window.open('Download.psp?param=hello','mywindow');" type="button" >Download</button>

Create a upload button
<button id="upload_trans_button" onclick="uploadTranslation();" type="button" disabled style="font-size:12px;">Upload</button>
<input id="form_trans" name="form_trans" type="file" style="height:28px;font-size:12px" onChange="b=$('upload_trans_button');if (this.value == ''){b.disabled=true;}else{b.disabled=false;}">