Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, June 11, 2012

Javascript | How to disable/enable the href functionality

Problem:
It's been a couple of days since I started solving the issue of href = "#", what I want is to disable it on certain occasion. Means there would be no active link will be shown on "Visit biboyatienza blogspot!" link, it should be display as a normal text no underline no mouse over.

From : Visit biboyatienza blogspot!


To : Visit biboyatienza blogspot!


Solution:
 var chk = document.getElementById('chkShoulBeActive');  
 if(chk != null)                 
 {  
                var hl = document.getElementById('hlSite');  
                if(hl != null)  
                {  
                     if(chk.checked)  
                          hl.addAttribute('href');  
                     else       
                          hl.removeAttribute('href');  
                }  
 }  

Hope you find it helpful

Wednesday, November 30, 2011

Disable ENTER Key javascript

javascript:



Add the following attribute into each TextBox in your form that should disable ENTER key :
onkeypress="return noenter()"

Thursday, November 24, 2011

ASP.NET TextBox MultiLine plus MaxLength

Solution:

javascript:
function checkTextAreaMaxLength(textBox,e, length)
{

var mLen = textBox["MaxLength"];
if(null==mLen)
mLen=length;

var maxLength = parseInt(mLen);
if(!checkSpecialKeys(e))
{
if(textBox.value.length > maxLength-1)
{
if(window.event)//IE
e.returnValue = false;
else//Firefox
e.preventDefault();
}
}
}
function checkSpecialKeys(e)
{
if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
return false;
else
return true;
}


How to used:

asp:TextBox Rows="5" Columns="80" ID="txtCommentsForSearch" MaxLength='1300' onkeyDown="checkTextAreaMaxLength(this,event,'1300');" TextMode="multiLine" runat="server"