Sunday, January 2, 2011

Sunday 1/02/2011

First post of the new year!

----- Talking about JavaScript:

I'm using a free design environment provided by Aptana Aptana

Every window object has a property called opener


<P>
<html>
<head>
<title>Main Document</title>
<script type="text/javascript">
function newWindow() {
window.open("subwind.htm" , "sub", "height=200, width=200");
}
</script>
</head>

<body>
<form>
<input type="button" value="New Window" onclick="newWindow()">
<br>
Text incoming from subwindow:
<input type="text" name="entry">

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

______________________________________________________

<html>
<head>
<title>A SubDocument</title>
</head>
<body>
<form onsubmit="return false">
Enter text to be copied to the main window:
<input type="text"
onchange="opener.document.forms[0].entry.value = this.value">
</form>
</body>
</html>



Most of the objects that a browser creates for you are established when an HTML document loads into the browser.

Remember that objects are create in their load order.

When used in script statements, property names are case-sensitive.

An objects method is a command that a script can give to that object.

Some methods return values, but that is not a prerequisite for a method.

An event handler specifies how an object reacts to an event that is triggered by a user action.


<html>
<head>
<title>A Simple Page</title>
<script type="text/javascript">


function modify() {

var newElem = document.createElement("p");
newElem.id = "newP";
var newText = document.createTextNode("This is the second paragraph.");
newElem.appendChild(newText);
document.body.appendChild(newElem);
document.getElementBYId("emphasis1").childNodes[0].nodeValue = "first";
}

</script>
</head>
<body>
<button onclick="modify()">Add/Replace Text</button>

<p id="paragraph1">This is the <em id="emphasis1">one and only</em> paragraph on the page.</p>

</body>
</html>


Here is a simple JavaScript code I wrote myself



<html>
<head>
<title>Checking for an existing, nonempty string</title>
<script type="text/javascript">
var textValue

function inputScript(){
alert("I am an alert box!");
textValue = document.frmOne.inputBox1.value;
alert(textValue);
}

</script>

</head>
<body>
<form name="frmOne">
<input type="text" name="inputBox1"></input>
<input type="submit" name="inputButton1" value="Enter" onclick="inputScript()">

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

No comments: