http://www.javascriptkit.com/script/script2/tengcalendar.shtml
Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts
Tuesday, May 10, 2011
Javascript | Clipboard
<html>
<head>
<title>Clipboard</title>
<script type=”text/javascript” language=”javascript”>
function SetClipBoard()
{
var email = document.getElementById(‘txtEmail’);
var emailValue = email.value;
window.clipboardData.setData(‘Text’ , emailValue );
}
function GetClipBoard()
{
var emailText = window.clipboardData.getData(‘Text’);
alert(emailText);
}
function ClearClipBoard()
{
window.clipboardData.clearData();
}
</script>
</head>
<body>
<form onreset=”return confirm(‘Do you want to reset the form?’)”>
<textarea name=”txtEmail” id=”txtEmail” rows=”4″ cols=”20″>Default Text</textarea>
<button onclick=”SetClipBoard();”>
Copy to Clipboard</button>
<button onclick=”GetClipBoard();”>
Get Clipboard Data</button>
<button onclick=”ClearClipBoard();”>
Clear Clipboard</button>
<input type=”reset” />
</form>
</body>
</html>
<head>
<title>Clipboard</title>
<script type=”text/javascript” language=”javascript”>
function SetClipBoard()
{
var email = document.getElementById(‘txtEmail’);
var emailValue = email.value;
window.clipboardData.setData(‘Text’ , emailValue );
}
function GetClipBoard()
{
var emailText = window.clipboardData.getData(‘Text’);
alert(emailText);
}
function ClearClipBoard()
{
window.clipboardData.clearData();
}
</script>
</head>
<body>
<form onreset=”return confirm(‘Do you want to reset the form?’)”>
<textarea name=”txtEmail” id=”txtEmail” rows=”4″ cols=”20″>Default Text</textarea>
<button onclick=”SetClipBoard();”>
Copy to Clipboard</button>
<button onclick=”GetClipBoard();”>
Get Clipboard Data</button>
<button onclick=”ClearClipBoard();”>
Clear Clipboard</button>
<input type=”reset” />
</form>
</body>
</html>
Javascript – Getting drop down values
<select id="ddlViewBy"> <option value="1">test1</option> <option value="2" selected="selected">test2</option> <option value="3">test3</option> </select>var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].value;var e = document.getElementById("ddlViewBy"); var strUser = e.options[e.selectedIndex].text;
JavaScript – Persist state of page using Hidden field
function showHide(divId,ImgId)
{
divstyle = document.getElementById(divId).style.display;
Image_ID=document.getElementById(ImgId);
if(divstyle.toLowerCase()==”block” && document.getElementById(‘<%=hdnShowHide.ClientID %>’).value==”0″)
{
document.getElementById(‘<%=hdnShowHide.ClientID %>’).value=”1″;
Hide();
}
else
{
document.getElementById(divId).style.display=”block”;
Image_ID.src=”/Images/uparrows_white.gif”;
document.getElementById(‘<%=hdnShowHide.ClientID %>’).value=”0″;
}
}
function Hide()
{
Image_ID=document.getElementById(‘img2′);
if(document.getElementById(‘<%=hdnShowHide.ClientID %>’).value==”1″)
{
Image_ID.src=”/Images/downarrows_white.gif”;
document.getElementById(‘divSearchCriteria’).style.display=”none”;
}
}
<asp:HiddenField ID=”hdnShowHide” runat=”server” Value=”0″ />
For user control:
At end of control’s HTML:
<script type=”text/javascript”>
Hide();
</script>
For page using content of master:
Use below code in script after hide function:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(Hide);
{
divstyle = document.getElementById(divId).style.display;
Image_ID=document.getElementById(ImgId);
if(divstyle.toLowerCase()==”block” && document.getElementById(‘<%=hdnShowHide.ClientID %>’).value==”0″)
{
document.getElementById(‘<%=hdnShowHide.ClientID %>’).value=”1″;
Hide();
}
else
{
document.getElementById(divId).style.display=”block”;
Image_ID.src=”/Images/uparrows_white.gif”;
document.getElementById(‘<%=hdnShowHide.ClientID %>’).value=”0″;
}
}
function Hide()
{
Image_ID=document.getElementById(‘img2′);
if(document.getElementById(‘<%=hdnShowHide.ClientID %>’).value==”1″)
{
Image_ID.src=”/Images/downarrows_white.gif”;
document.getElementById(‘divSearchCriteria’).style.display=”none”;
}
}
<asp:HiddenField ID=”hdnShowHide” runat=”server” Value=”0″ />
For user control:
At end of control’s HTML:
<script type=”text/javascript”>
Hide();
</script>
For page using content of master:
Use below code in script after hide function:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != ‘function’) {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(Hide);
JavaScript – window.close() isn’t working in mozilla firefox
Use the following code instead of “window.close();”
function winClose(){ window.top.opener = null; window.close(); }
or
function closeWindow() { window.open(”,’_parent’,”); window.close(); }
If it doesn’t works
Please set your firefox browser:
1.input “about:config ” to your firefox address bar and enter;
2.make sure your “dom.allow_scripts_to_close_windows” is true
function winClose(){ window.top.opener = null; window.close(); }
or
function closeWindow() { window.open(”,’_parent’,”); window.close(); }
If it doesn’t works
Please set your firefox browser:
1.input “about:config ” to your firefox address bar and enter;
2.make sure your “dom.allow_scripts_to_close_windows” is true
JavaScript – Upload multiple images
<script type=”text/javascript” language=”javascript”>
function AddMoreImages()
{
if (!document.getElementById && !document.createElement)
return false;
var fileUploadarea = document.getElementById(“fileUploadarea”);
if (!fileUploadarea)
return false;
//var newFile = document.createElement(“input”);
// newFile.type = “file”;
var deletediv = document.createElement(“DIV”);
if (!AddMoreImages.lastAssignedId)
AddMoreImages.lastAssignedId = 100;
// newFile.setAttribute(“id”, “FileUpload” + AddMoreImages.lastAssignedId);
// newFile.setAttribute(“name”, “FileUpload” + AddMoreImages.lastAssignedId);
deletediv.innerHTML=’<input id=”file’ + AddMoreImages.lastAssignedId + ‘” name = “file’ + AddMoreImages.lastAssignedId + ‘”class=fileUpload type=”file” />’ + ‘<input id=”Button’ + AddMoreImages.lastAssignedId + ‘”class=deleteBtn type=”button” ‘ + ‘value=”Delete” onclick = “RemoveFileUpload(this)” />’;
//newFile.className=”fileUpload”;
var div = document.createElement(“div”);
//div.appendChild(newFile);
div.appendChild(deletediv);
div.setAttribute(“id”, “div” + AddMoreImages.lastAssignedId);
fileUploadarea.appendChild(div);
AddMoreImages.lastAssignedId++;
}
function RemoveFileUpload(div)
{
document.getElementById(“fileUploadarea”).removeChild(div.parentNode.parentNode);
}
</script>
function AddMoreImages()
{
if (!document.getElementById && !document.createElement)
return false;
var fileUploadarea = document.getElementById(“fileUploadarea”);
if (!fileUploadarea)
return false;
//var newFile = document.createElement(“input”);
// newFile.type = “file”;
var deletediv = document.createElement(“DIV”);
if (!AddMoreImages.lastAssignedId)
AddMoreImages.lastAssignedId = 100;
// newFile.setAttribute(“id”, “FileUpload” + AddMoreImages.lastAssignedId);
// newFile.setAttribute(“name”, “FileUpload” + AddMoreImages.lastAssignedId);
deletediv.innerHTML=’<input id=”file’ + AddMoreImages.lastAssignedId + ‘” name = “file’ + AddMoreImages.lastAssignedId + ‘”class=fileUpload type=”file” />’ + ‘<input id=”Button’ + AddMoreImages.lastAssignedId + ‘”class=deleteBtn type=”button” ‘ + ‘value=”Delete” onclick = “RemoveFileUpload(this)” />’;
//newFile.className=”fileUpload”;
var div = document.createElement(“div”);
//div.appendChild(newFile);
div.appendChild(deletediv);
div.setAttribute(“id”, “div” + AddMoreImages.lastAssignedId);
fileUploadarea.appendChild(div);
AddMoreImages.lastAssignedId++;
}
function RemoveFileUpload(div)
{
document.getElementById(“fileUploadarea”).removeChild(div.parentNode.parentNode);
}
</script>
JavaScript – encodeURIComponent() Function
Definition and Usage
The encodeURIComponent() function encodes a URI component.
This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
Tip: Use the decodeURIComponent() function to decode an encoded URI component.
Syntax
Browser Support
The encodeURIComponent() function is supported in all major browsers.
Example Encode an URI:
The output of the code above will be:
http%3A%2F%2Fgorav.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
The encodeURIComponent() function encodes a URI component.
This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #
Tip: Use the decodeURIComponent() function to decode an encoded URI component.
Syntax
| encodeURIComponent(uri) |
| Parameter | Description |
| uri | Required. The URI to be encoded |
The encodeURIComponent() function is supported in all major browsers.
Example Encode an URI:
| <script type=”text/javascript”> var uri=”http://gorav.com/my test.asp?name=stÃ¥le&car=saab”; document.write(encodeURIComponent(uri)); </script> |
http%3A%2F%2Fgorav.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab
Subscribe to:
Posts (Atom)