• Archives

  • Archive for the ‘Javascript’ Category

    Using get element by id

    Thursday, January 17th, 2008

    Get element by id is a function which will return the the content inside a element for example

    Example

    <html>

    <head>

    <script type=”text/javascript” >

    function gebid(){

    var xyz=document.getElementById(“text”);

    alert(xyz.innerHTML);

    }

    </script>

    </head>

    <body>

    <h1 id=”text” onclick=”gebid()”>You will see this same text when you will click here</h1>

    </body>

    </html>

    Thanks

    krates

    Changing the image on hovering through javascript

    Tuesday, January 8th, 2008

    This tutorial is going to teach you how to change the image when you hover your mouse over it throught javascript:

    Have a look below:

    <html>
    <head>
    <script type=”text/javascript”>
    function onhover()
    {
    document.imagel.src=”image1.gif”;
    }
    function hoverout()
    {
    document.imagel.src=”image2.gif”;
    }
    </script>
    </head>

    <body>
    <a href=”http://www.easytutorial.info” target=”_blank”>
    <img border=”0″ alt=”Easytutorials for you” src=”image1.gif” name=”imagel” height=”20″ onmouseover=”onhover()” onmouseout=”hoverout()” /></a>
    </body>
    </html>

    Thanks
    krates

    How to create a pop up window tutorial

    Saturday, December 29th, 2007

    OK guys here is the tutorial which many of you want how to create a pop up window which you must have seen in many of the wbesites

    First of all create a simple html file:

    <html>

    <head>

    </head>

    <body>

    </body>

    </html>

    Done

    Now add the add the following code below head tag

    <script language=”JavaScript”>
    <!–
    function popup(url,windowtitle,specification) {

    window.open(url,windowtitle,specification);
    }
    //–>

    </script>

    The above function will first tell the browser to read the below lines as JavaScript code

    If your browser is old this code <!– will tell the browser to read it is as comment and perform no action

    Then you will create a function popup

    With three arguments url,windowtitle,specification

    Done

    Now below <body> add following code

    <a href=”javascript:;”onClick=”popup(‘http://www.yahoo.com’,’Yahoo’,’width=540,height=480′)”>Click me </a>

    Done

    <html>
    <head>
    <script language=”JavaScript”>
    <!–
    function popup(url,windowtitle,specification) {
    window.open(url,windowtitle,specification);
    }
    //–>
    </script>
    </head>
    <body>
    <a href=”javascript:;”onClick=”popup(‘http://www.yahoo.com’,’Yahoo’,’width=540,height=480′)”>Click me </a>
    </body>
    </html>

    For example click below





    Click me

    Thanks
    krates

    Creating a button to select everything in a text area.

    Monday, December 10th, 2007

    Here is a simple script sometimes you want to highlight verything in a text field so that the user can copy it or something.

    script goes here

    <form>
    <center>
    <input type=button value=”Highlight All” onClick=”javascript:this.form.textarea.focus();this.form.textarea.select();”>

    <br>

    <textarea NAME=”textarea” ROWS=10 COLS=30 WRAP=VIRTUAL>

    Put all the content over here.

    Thanks kushagra
    </textarea>
    </center>
    </form>

    just notice one the textarea name is textarea and

    javascript:this.form.textarea.focus();this.form.textarea.select();

    Change every textarea word with the name of your text area

    and for a google type by just clicking on textarea everything gets selected you can do\

     <form>
    <center>

    <textarea NAME=”textarea” ROWS=10 COLS=30 WRAP=VIRTUAL onClick=”javascript:this.form.textarea.focus();this.form.textarea.select();”>

    Put all the content over here.

    Thanks kushagra
    </textarea>
    </center>
    </form>

    thanks

    krates

    Confirming actions in javascript

    Monday, December 3rd, 2007

    Sometimes if a user is navigating away from your site or some hyperlink is there which is going to click u can add a confirm box so that he can change his decision or you show him something more intresting

    Using Confirm:

    <html>
    <head>
    <script type=”text/javascript”>
    function confirmaction()
    {
    var action=confirm(“Choose action”);
    if (action==true)
    {
    document.write(“You have pressed ok”);
    }
    else
    {
    document.write(“You have pressed Cancel”);
    }
    }
    </script>
    </head>
    <body>
    <input type=”button” onclick=”confirmaction()” value=”Button” />
    </body>
    </html>

    Example explained

    Now when you will click on the button

    the confirm command works and it will display

    a command prompt with a OK and CANCEL button if you pressed ok

    The action becomes true and the statement

    You have pressed ok

    will be displayed

    and the vice – versa (Reverse) If you pressed cancel

    Thanks

    krates