Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Tuesday, September 25, 2012

Find selected item from radiobutton list using javascript

ASP.NET renders a table and a bunch of other mark-up around the actual radio inputs  

 var list = document.getElementById("rdbdesc"); 
    var inputs = list.getElementsByTagName("input"); 
    var selected;  
    for (var i = 0; i < inputs.length; i++)  
    {      
    if (inputs[i].checked) { 
    selected = inputs[i];     
    break;   
    }    
    }   
    if (selected)
    {
       
    alert(selected.value);   
   
    }
  

Tuesday, September 11, 2012

Add /Remove controls on Multple Select Option using JavaScript

Add /Remove  controls on Multple Select Option using JavaScript
<script language="javascript">

    function loopSelected()
    {
          var PIOID = document.getElementById('PIOID');
        var ExistingControl1='';
        var selectedArray = new Array();
        var selObj = document.getElementById('selMulPio');
        var i;
        var count = 0;
        for (i=0; i<selObj.options.length; i++) {
                if (selObj.options[i].selected) {
                    ExistingControl1=ExistingControl1+"<textarea id='txt"+i+"'></textarea>";
                                 }
        }
            PIOID.innerHTML=null;   
            PIOID.innerHTML = ExistingControl1;

    }
</script>

<select name="pio[]"  id="selMulPio"  multiple="multiple"  style="width:100px; height:120px;" onchange="loopSelected();">
<option value="1">India</option>
<option value="2">USA</option>
<option value="3">PAK</option>
</select>
<br>
<div id="PIOID"></div>


=================================
example:-
=================================


Friday, July 20, 2012

Play Wav Sound File in Asp.net Using Java Script

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var soundObject = null;
        function PlaySound() {
            if (soundObject != null) {
                document.body.removeChild(soundObject);
                soundObject.removed = true;
                soundObject = null;
            }
            soundObject = document.createElement("embed");
            soundObject.setAttribute("src", "sounds/song1.wav");
            soundObject.setAttribute("hidden", true);
            soundObject.setAttribute("autostart", true);
            document.body.appendChild(soundObject);
        }
    </script>
</head>
<body>
    <form id="frm1" runat="server">
        <input type = "btn" onclick = "PlaySound()" value = "Play Sound" />
    </form>
</body>
</html>


ref: Click Here 

Tuesday, February 14, 2012

Using javascript check uploaded file size

write function in JavaScript

Note:- Only working with FireFox,Crome,Safari,Opera 
for Internet Explorer check this page

function aditya(source, args)
    {
    arguments.isvalid = false;
    fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
    file=fileupload.files[0];
    if (file.size<1048576)
    {
     args.IsValid =  true;
    }
    else
    {
     args.IsValid = false ;
    }
    return ;
    }

use this function in Custom Validator Field
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2" ClientValidationFunction="aditya"></asp:CustomValidator>




==========================================================================
Example:---

==========================================================================





<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">
    function aditya(source, args)
    {
    arguments.isvalid = false;
    fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
    file=fileupload.files[0];
    if (file.size<1048576)
    {
     args.IsValid =  true;
    }
    else
    {
     args.IsValid = false ;
    }
    return ;
    }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload2" runat="server" />
        <asp:RegularExpressionValidator ID="ValidateResume" runat="server" ErrorMessage="Only pdf files allowed."
            ValidationExpression="^.+\.(([pP][dD][fF]))$" ControlToValidate="FileUpload2" />
        <asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2"
            ClientValidationFunction="aditya"></asp:CustomValidator>
    </div>
    </form>
</body>
</html>



Wednesday, January 25, 2012

Print using JavaScript in Asp.Net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="test.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" >
    function print() {

            var printWindow = window.open('', '', 'status=1,width=800,height=600');
            printWindow.document.write(document.getElementById('<%=adityadiv.ClientID%>').innerHTML);
            printWindow.document.close();
            printWindow.print();
            printWindow.close();
        }
       </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="adityadiv" runat="server">
    this is a demo of print button.
    in this tutorial we r opening print dailog using javascript.
   
    <ol>
    <li>aditya pratap singh</li>
    <li>india</li>
    <li>lucknow</li>
    <li>new delhi</li>
    <li>gorakhpur</li>
    <li>chennai</li>
    </ol>
    </div>
   <input id="printbtn" type="button"  onclick="print()" value="Print" runat="server" alt="Print"/>
  
    </form>
</body>
</html>

Thursday, January 19, 2012

How to enable JavaScript in Browsers?




Internet Explorer 5 and above

  • 1. Select Internet Options from the Tools menu.
  • 2. In Internet Options dialog box select the Security tab.
  • 3. Click the Custom Level... button. The Security Settings dialog box will pop up.
  • 4. Under Scripting category enable Active scripting.
  • 5. Click OK twice to close out.
  • 6. Click Refresh.


Netscape 7.X

  • 1. Select Preferences from the Edit menu.
  • 2. Click the arrow next to Advanced.
  • 3. Click Scripts & Plug-in.
  • 4. Check Navigator beneath "Enable JavaScript for".
  • 5. Click OK.
  • 6. Click Reload.


Netscape 6.X

  • 1. Select Preferences from the Edit menu.
  • 2. Click Advanced
  • 3. Check Enable JavaScript for Navigator
  • 4. Click OK.
  • 5. Click Reload.


Opera 7.X

  • 1. Select Quick Preferences from the File menu.
  • 2. Make sure Enable JavaScript is checked.
  • 3. Click Reload.


Mozilla 3.6.X and above

  • 1. Select Options from the Tools Menu
  • 2. Select Content tab
  • 3. Make sure Enable JavaScript is checked


Safari 4.X

  • 1. Select Preferences from the Edit menu.
  • 2. Click the Security tab.
  • 3. Click Scripts & Plug-in.
  • 4. Check "Enable JavaScript".
  • 5. Close Security window.
  • 6. Close and reopen the browser.

Google Crome 8.X

  • 1. Select Setting from menu.
  • 2. Click the Options.
  • 3. Click Under the Hood  tab.
  • 4. Click on "Content Settings" Button under "Privecy" section.
  • 5. Click on Javascript under features. 
  • 6. Click on "Allow all sites to run Java Script".
  • 7. Close and reopen the browser.



Note: Instructions may vary with different browsers and operating systems. If you cannot locate the JavaScript settings, check the help topics for the browser being used.


Monday, December 19, 2011

Create Water Mark Text Box using JavaScript

we can create this using JavaScript code is given below:
----------------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
         <script language="javascript" type="text/javascript">
        function Focus(objname, waterMarkText) {
            obj = document.getElementById(objname);
          
                obj.value = "";
                if (obj.value == "Aditya" || obj.value == "" || obj.value == null) {
                    obj.style.color = "black";
             
            }
        }
        function Blur(objname, waterMarkText) {
            obj = document.getElementById(objname);
            if (obj.value == "") {
                obj.value = waterMarkText;
                                             
            }
                  if (obj.value == "Aditya" || obj.value == "" || obj.value == null) {
                obj.style.color = "gray";
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <table>
        <tr>
            <td>
                User Name
            </td>
            <td>
                <asp:TextBox ID="txtUserId" runat="server"
        onfocus="Focus(this.id,'Aditya')"
                    onblur="Blur(this.id,'Aditya')"
            Width="126px" style="background-color:pink" >Aditya</asp:TextBox>
            </td>
        </tr>
      </table>
    </form>
</body>
</html>
------------------------------------------------------------------------------------
try this