Friday, 27 December 2013

How do I update two frames at once?

Using JavaScript :

Using the scripting language JavaScript, a small script can be written to update two frames at once. It would lookb basically as follows:

<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
function fnUpdate(){
   top.frame1.location="URL1";
   top.frame2.location="URL2";
}
// -->
</SCRIPT>
...

<A HREF="URL1" TARGET=frame1 onClick="fnUpdate();">Update frames</A>
 
The names frame1 and frame2 would have to be replaced with the names of the actual frames you want to have updated. Using the link above, if the browser does not support Javascript (or has it disabled), only the first frame will be updated.

 Source : http://www.stack.nl/htmlhelp/design/frames/faq/faq.html

Monday, 27 May 2013

How to check current date and time using Javascript

<html>
<head>
<title>Today's Date</title>
    <script LANGUAGE="JavaScript">
    // Define a function for use later on.
    function todays_date()
    {
        var d = new Date();  // today's date and time.
        document.write(d.toLocaleString());
    }
    </script>
</head>
<body>
<hr>The date and time are:<hr><b>
    <script LANGUAGE="JavaScript">
    // now call the function we defined above
    todays_date();
    </script>
</b><hr>
</body>
</html>

Drop down selection enabling text box


<html>
<head>

<script type="text/javascript">

function Disable(aList)
{
var x=document.getElementById("text")
x.disabled=(aList.selectedIndex == 0);
}

function init()
{
document.getElementById("selectList").selectedIndex=1;
}
</script>

</head>
<body onload="init()">

<form>
<select id="selectList" onchange="Disable(this)">
<option >Off</option>
<option>On</option>
</select>
<input type="text" id="text">
</form>

</body>
</html>

Saturday, 6 April 2013

JavaScript Popup window code


Example for Popup window code :


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
 popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<p>Popup Window:</p>
<p><a href="JavaScript:newPopup('http://www.njsss.wordpress.com');">Click Here</a></p>
</body>
</html>



JavaScript has three kind of popup boxes: 

1.Alert box.
2.Confirm box.
3.Prompt box.


1.Alert Box :

An alert box is often used if you want to make sure information comes through to the user.
Syntax :
window.alert("Enter text here");


<script>
function myFunction()
{
alert("alert box!");
}
</script>
 

<input type="button" onclick="myFunction()" value="click here" />

2.Confirm Box :

A confirm box is often used if you want the user to verify or accept something.
Syntax :
window.confirm("Enter text here");


Example :

<p>confirm box.</p>
<button onclick="myFunction()">click Here</button>
<p id="Test"></p>
<script>
function myFunction()
{
var x;
var r=confirm("Press a button confirm!");
if (r==true)
  {
  x="Thanks!";
  }
else
  {
  x="Sorry!";
  }
document.getElementById("Test").innerHTML=x;
}
</script>


3.Prompt Box

A prompt box is often used if you want the user to input a value before entering a page.
Syntax :
window.prompt("sometext","defaultvalue");


Example :

<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">click Here</button>
<p id="Test"></p>
<script>
function myFunction()
{
var x;
var person=prompt("Please enter your name","Steve");
if (person!=null)
  {
  x="Hello " + person + "Welcome to Bangalore";
  document.getElementById("Test").innerHTML=x;
  }
}
</script>

Tuesday, 2 April 2013

JavaScript replace() Method


 JavaScript replace() Method :


<!DOCTYPE html>
<html>


<body>
<p id="demo">Hello Steve</p>

<button onclick="myFunction()">Replace</button>

<script>
function myFunction()
{
var str=document.getElementById("demo").innerHTML;
var n=str.replace("Steve","jhon");
document.getElementById("demo").innerHTML=n;
}
</script>

</body>
</html>


Output :
Click the Replace button to replace "steve" with "jhon" in the paragraph below

Choose dropdown options using JavaScript

Choose dropdown options using JavaScript :
select, options, selectedIndex, selected


<html>
<head>


<script type="text/javascript">
function selectOption(num)
{
    var selObj = document.getElementById('Demo');
    selObj.selectedIndex = num;
}

function alertSelectedIndex(selId)
{
    alert('selectedIndex for ' + selId + ' is: '
     + document.getElementById(selId).selectedIndex);
}
</script>
</head>
 

<body>
<form>

<h3>Choose one option at a time</h3>

<select name="selSS1" id="Demo">
    <option value="val0">sea zero</option>
    <option value="val1">sea one</option>
    <option value="val2">sea two</option>
    <option value="val3">sea three</option>
    <option value="val4">sea four</option>
</select>


<input type="button" value="0" onclick="selectOption(0);" />
<input type="button" value="1" onclick="selectOption(1);" />
<input type="button" value="2" onclick="selectOption(2);" />
<input type="button" value="3" onclick="selectOption(3);" />
<input type="button" value="4" onclick="selectOption(4);" />
<input type="button" value="alert" onclick="alertSelectedIndex('Demo');" />

</form>
</body>
</html>

Disable Select Box


DISABLE attribute for the SELECT tag :

 

Example :

<html>
<body>

<script type="text/javascript">
<!--
function disable(disableIt)
{
    document.Demo.select.disabled = disableIt;
}
//-->
</script>

<form name="Demo">
<select name="select">
<option value="1">Name</option>
<option value="2">Date</option>
</select>
<br />
<input type="checkbox" onclick="disable(this.checked)" /> Disable
</form>

</body>
</html>