Sunday, August 23, 2015

Dynamic positioning (TEXT GROWING IN HTML) USING JS

<html>
<head>
<script>
var flag=1,fontsize=2;
function start()
{
setInterval("change()",100);
}
function change()
{
h.style.fontSize=fontsize;
h.innerText+=fontsize;
if(fontsize==500)
fontsize=0;

fontsize++;
if(flag==1)
{
document.body.style.backgroundColor="red";
flag=0;
}
else
{
document.body.style.backgroundColor="green";
flag=1;
}
}

</script>
</head>
<body onload="start()">
<p id="h">Hi Welcome</p>

</body>
</html>

Change the background color dynamically using java script

<html>
<head>
<script>

function start()
{
document.body.style.backgroundColor="red";
}

</script>
</head>
<body>
<p>Hi Welcome</p>
<input type="button" onclick="start()" value="Click me" >
</body>
</html>

Collections CHILDREN in html using JS

Collections: 
It is an array of all the elements(tags) that are present in the html page.

documemt.all==> Is a collection/array of all the elements in the html page in the order in which they appear on the html page..

documemt.all.length==>Is used to find out howmany elements/tags are there in the html page.

document.all[index].children==>Is an array/collection of all the immediate child-elements of the all[index] element.

document.all[index].children.length==>Is used to find out howmany elements/tags are there inside the all[index] element/tags.

<html>
<head>
<script>
var data=" THE TAGS ARE:";
function start()
{
for(var i=0;i<document.all.length;i++)
{
data+=" <br><br> TAG: "+document.all[i].tagName;
if(document.all[i].children.length>0)
data+="   <b> ITS CHILD : </b>";
for(var j=0;j<document.all[i].children.length;j++)
data+=" "+document.all[i].children[j].tagName;
}

para.innerHTML+=data;
}

</script>
</head>
<body>
<p id="para">Hi Welcome</p>
<input type="button" onclick="start()" value="Click me" >
</body>
</html>

COLLECTIONS IN HTML (Dynamic Object Model Using JS)

Collections: 
It is an array of all the elements(tags) that are present in the html page.

documemt.all==> Is a collection/array of all the elements in the html page in the order in which they appear on the html page..

documemt.all.length==>Is used to find out howmany elements/tags are there in the html page.

document.all[index].children==>Is an array/collection of all the immediate child-elements of the all[index] element.

document.all[index].children.length==>Is used to find out howmany elements/tags are there inside the all[index] element/tags.


<html>
<head>
<script>
var data=" THE TAGS ARE:";
function start()
{
for(var i=0;i<document.all.length;i++)
data+="  "+document.all[i].tagName;
para.innerText+=data;
}

</script>
</head>
<body>
<p id="para">Hi Welcome</p>
<input type="button" onclick="start()" value="Click me" >
</body>
</html>

Saturday, August 22, 2015

IMAGE SWITCHER Android Example

package com.example.vadivelanudayakumar.imageswitch;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;


public class MainActivity extends ActionBarActivity {

    int[] images={R.drawable.vv,R.drawable.browser,R.drawable.facebook,R.drawable.gmail,R.drawable.ln,R.drawable.gmaill,R.drawable.twitter,R.drawable.you};
    int counter=0;
    ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img=(ImageView)findViewById(R.id.imageView);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void next(View v){
 
    img.setImageResource(images[counter]);
        counter++;
        if(counter>=images.length)
            counter=0;
    }
}

Email In Android


    public void send(View v)
    {
        Intent i=new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_EMAIL,"vadivelan.1205237@srec.ac.in");
        i.putExtra(Intent.EXTRA_SUBJECT,"EMAIL SUBJECT");
        i.putExtra(Intent.EXTRA_TEXT,"EMAIL msg");
        i.setType("message/rfc822");
        startActivity(Intent.createChooser(i,"MAIL"));
        Toast.makeText(this.getApplicationContext(),"Sending",Toast.LENGTH_LONG);
    }

Tuesday, August 18, 2015

OTHER AVERAGE CALCULATION ALGORITHM

AVERAGE CALCULATION ALGORITHM


normally we calculate average as :

             x1+x2+.........+xn
avg =  ---------------------
                      n











MY ALGORITHM:


                      (xn-x1)+(xn-x2)+......(xn-x(n-1))                                           
avg = x1  +   -----------------------------------                                         
                                            n                                                                     

here, xn is the largest no.


THIS WORKS GOOD FOR 2nos
ie

102.75 and 103.6


traditional avg=(102.75+103.6)/2

BY THIS METHOD

avg=102.75 + (0.85/2) = 103.175

Friday, August 7, 2015

HOW TO AVOID CLICKS OR COPYING FROM A WEBPAGE

<html>
<head>
<script>
//TO PREVENT CLICKS
document.onmousedown=sia;function sia()
{
window.alert("Clicks Not Allowed");
}
</script>
</head>
<body bgcolor="#EAEAEA" ondragstart="return false" onselectstart="return false">




YOU CANNOT COPY THIS CONTENT
:-P


</body>
</html>