JavaScript
Validate radio button in datagrid, datalist, gridview on button
Here ‘questionlist’ is the id of Datalist or datagrid or Gridview or repeater
u call this function on button events
<button onclick=”return isconfirm()” />
<script language=javascript>
function isconfirm()
{
var counter=0;
var obj=document.getElementById(“<%=questionlist.ClientID%>”).getElementsByTagName(“input”);
for(i=0;i<=obj.length-1;i++)
{
if(obj[i].type==”radio” && obj[i].checked==true)
{
counter++;
}
}
if(counter==0)
{ alert(‘Plz Select question Answer’);
return false
}
return true;
}
</script>
TextBox with numeric input only : textbox, only, numeric, input
function ISonlynumber(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
<asp:TextBox ID=”txtmobileNO” Runat=”server” Width=”150″ MaxLength=”64″ onkeypress=”javascript:return ISonlynumber(event);”></asp:TextBox>
Set dropdownlist value from querystring in javascript
<script language=javascript>
function SetSetectedVelue()
{
var id=’<%=Request.QueryString["cityid"] %>’;
if(id.length==0)
id=1;
var city=document.getElementById(‘<%=ddlcity.ClientID%>’);
for(var i=0;i<city.length;i++)
{
if(city.options[i].value==id)
city.selectedIndex=i;
}
}
</script>
<body onload=”SetSetectedVelue()”>
<form id=”form1″ runat=”server”>
<div>
<asp:DropDownList id=”ddlcity” runat=server >
<asp:ListItem value=”1″ >delhi</asp:ListItem>
<asp:ListItem value=”2″>mumbai</asp:ListItem>
<asp:ListItem value=”3″>channai</asp:ListItem>
<asp:ListItem value=”4″>kolkota</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
Display Rss data througth Javascript
function GetXmlHttpObject()
{
/*extern ActiveXObject, XMLHttpRequest */
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}
function displayRSS(url)
{var xmlhttp=GetXmlHttpObject();
if(xmlHttp==null)
{return;}
xmlHttp.open(“GET”,url,true);
xmlHttp.onreadystatechange=getRssFormat;
xmlHttp.send(null);
}
function getRssFormat()
{if(xmlHttp.readyState==4)
{if(xmlHttp.status != 200)
{
document.getElementById(“rss”).innerHTML= “<br><br><br>Sorry….<br><br><br><br>The Server did not return any results (Result code: 200)<br><br><br><br>Please try again<br><br>Sorry for the Inconvenience”;
}
else{
var items_count=3;
link=new Array(), title=new Array(), pubDate=new Array()
for(var i=0; i<items_count; i++) {
if(items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘link’).length==1)
link[i]=items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘link’)[0];
if(items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘title’).length==1)
title[i]=items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘title’)[0];
if(items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘pubDate’).length==1)
pubDate[i]=getDateFormat(items.getElementsByTagName(‘item’)[i].getElementsByTagName(‘pubDate’)
[0].firstChild.nodeValue);
}
if(title.length==0)
return false;
var ws=/\S/;
ul = document.createElement(“ul”);
var mydiv = document.getElementById(“rss”);
mydiv.appendChild(ul);
for(var [...]
Get web control value through javascript
<asp:TextBox id=”txtname” runat=server ></asp:TextBox>
<script>
function getvalue()
{
var val=document.getElementById(‘<%=txtname.ClientID%>’).value;
alert(val);
}
page bookmark in javascript
var urlAddress =window.location.href;
var pageName = document.title;
function addToFavorites()
{
if (window.external)
{
window.external.AddFavorite(urlAddress,pageName)
}
else
{
alert(“Sorry! Your browser doesn’t support this function.”);
}
}
show hide layer on tab clicking
function showDiv(dvnm)
{
document.getElementById(dvnm).style.display = ‘block’;
document.getElementById(dvnm).style.visibility = ‘visible’;
}
function hideDiv(dvnm)
{
document.getElementById(dvnm).style.display = ‘none’;
document.getElementById(dvnm).style.visibility = ‘hidden’;
}
function showlayer(n)
{
for(i=1;i<=2;i++)//number of layer u want to show
{
if(i==n)
{
showDiv(‘div’+ i);//dynamically call div id
document.getElementById(‘tab’+i).style.backgroundColor=”#666666″;//dynamically show contant id
}
else
{
hideDiv(‘div’+ i);
document.getElementById(‘tab’+i).style.backgroundColor=”gray”;
}
}
}
show and hide content on next prev button
<table width=”99%” cellpadding=”3″ cellspacing=”1″ bgcolor=”#000000″>
<tr>
<td height=”20″ class=”photonamewhite”><div style=”float: right; width: 100px; position: relative; height: 25px;” class=smallphotoname align=”right”><a href=”#” class=”curhand” title=”Previous” onclick=”moveRight(‘div_hall’,90)”>«prev</a> <a href=”#” title=”next” onclick=”moveLeft(‘div_hall’,90)”>next»</a></div></td>
</tr>
<tr>
<td bgcolor=”#999999″ >
<DIV style=”MARGIN-LEFT: 5px; OVERFLOW: hidden; background-color:#666666; WIDTH: 276px; POSITION: relative; HEIGHT: 184px”>
<DIV id=”div_hall” style=”LEFT: 0px; WIDTH:<%=(photo.Items.Count%6)==0?(photo.Items.Count/6)*270:((photo.Items.Count/6)+1)*270%>px; POSITION: absolute; TOP: 0px”>
<asp:DataList ID=photo runat [...]
send data from html page to server pages
head>
<title>Untitled Page</title>
<script language=javascript>
function submitvalue()
{
var red=document.getElementById(‘rd’);
var val=“PH”;
if(rd[0].checked==true)
{val=“KH”;
}
window.location.href=“keywordsearch.aspx?kq=”+document.getElementById(‘txtsearch’).value+“&stype=”+val;
}
</script>
</head>
<body>
<input type=text name=”txtsearch” runat=server />
<input type=radio name=”rd” value=”KH” runat=server checked=checked/>
<input type=”radio” name=”rd” value=”PH” runat=server/>
<input type=”button” name=”btnsearch” value=”search” onclick=”submitvalue();”/>
</body>
Open .aspx page with parameter in popup window
<a href=”javascript:return false;” onclick=”javascript:window.open(’sendquery.aspx?rg=” + sd.REGID + “&comp=” + sd.COMPANYNAME + “&city=” + sd.CITYNAME + “‘,’smallwindowsms’,’toolbars=0,crollbars=0,width=600,
height=500,menubar=0,resizable=0′);return false;”>send query</a>
« Previous Entries


