Category: Javascript & Jquery
-
how to replace & or special characters in javascript?
//if value of catnm=’art & jewllery‘; //then i want need to replace “&“. //because when i will try to post data using jquery then jquery know this is query string…..so i want to need to replace “&” using “URL ENCODED CHARACTERS” //so,see below example var catnm=document.getElementById(‘catnm’).value; var cat_re=catnm.replace(‘&’,’%26′); OUTPUT In Javascript alert box : art…
-
how to validate multiple select box with jquery?
$(“#form”).validate({ rules:{ “select_esp[]”: “required” }, messages:{ “select_esp[]”: “Select this” } });
-
How to enable/disable element in Javascript
If u want to enable or disable any HTML element using javascript in asp.net/php u can use the following code, document.getElementById(‘nm’).disabled=’disabled’ ; and the below code will enable the element, document.getElementById(‘nm’).disabled=”;
-
how to make captcha in php?
Captcha Code: <?php session_start(); $num=”; $string = “abcdefghijklmnopqrstuvwxyz0123456789”; for($i=0;$i<7;$i++){ $num1=rand(0,35); $num .= $string{$num1}; } $_SESSION[“num1”]=$num; $img=imagecreatefrompng(‘captcha.png’); $color=imagecolorallocate($img,255,255,255); $color1=imagecolorallocate($img,0,0,0); imagestring($img,9,10,3,$num,30); $fontsize=20; $fontcolor = imagecolorallocate($img, 0, 0, 0); $x = 0; $y = $fontsize; header(‘Content-type : image/png’); imagepng($img); imagedestroy($img); ?> How to use in php? <img id=”cap” style=”margin-left: 15px;” src=”comman/captcha.php” alt=”” /> How to refresh captcha? Call…
-
How to launch jQuery Fancybox on page load?
//first include fancybox javascript file and jquery javascript file. <script type=”text/javascript”> jQuery(document).ready(function() { $(“a#various2”).trigger(‘click’); }); </script>
-
how to remove any character using javascript?
I am removing only ” – (dash), . (dot), (space) in this exmple. function dotrm(cit) { var cl=cit.length; var ch=cit; for(l=0;l<=cl;l++) { if(cit[l] == ‘.’ || cit[l] == ‘ ‘ || cit[l]==’-‘) { ch=cit.replace(cit[l],”); } } document.getElementById(“city”).value=ch; }
-
how to validate password allow space in middle of string
function spc(str) { var l=str.length;//check length of string for(var i=0;i<l;i++) { if(str[0]==’ ‘ || str[str.length-1]==’ ‘)//check first & last character of password { document.getElementById(“spa_error”).innerHTML=’Space key cannot be used for the first or last character of your password’; }else { document.getElementById(“spa_error”).innerHTML=”; } } }
-
how to use trim() function in IE below version
Use this function in head section of your webpage and then use trim() function. if(typeof String.prototype.trim !== ‘function’) { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ”); } }
-
How to add top and bottam pagination in datatable?
First open jquery.datatables.js file and find this.sDom = ‘lfrtip’; or this.sDom and then write below code inplace of previous code. this.sDom = ‘<“top”iflp>t<iflp>’;
-
How to validate multiple checkbox?
var adfa=0; var chk=document.getElementById(“tbl”);//table id for(var i=0;i < chk.rows.length;i++) { var inputs = chk.rows[i].getElementsByTagName(‘input’); if(inputs[0].checked==true) { adfa=1; } } if(adfa==1) { //alert(“true”); if(val==’delete’){ var ans=confirm(‘Are you sure want to delete?’); if(ans) document.forms[id].submit(); } }else { alert(“No entry was selected to be deleted”); }
