<html>
<head>
<title>Validator</title>
// This is from the book JavaScript Bible (5th Edition) by Danny Goodman and Michael morrison
<script type="text/javascript">
function checkForm(form) {
for (var i = 0; i < form.elements.length; i++) {
if (form.elements[i].value =="") {
alert("Fill out ALL fields.");
return false;
}
}
return true;
}
</script>
</head>
<body>
<form onsubmit="return checkForm(this)">
Please enter all requested information:<br>
First Name:<input type="text" name="firstName"><br>
Last Name:<input type="text" name="lastName"><br>
Rank:<input type="text" name="rank"><br>
serial Number:<input type="text" name="serialNumber"><br>
<input type="submit">
</form>
</body>
</html>
Here is another tutorial. In this tutorial, in the <body> the first script runs as the page loads, setting a global variable (today) to the current date and time.
<html>
<head>
<title>Date Calculation</title>
<script type="text/javascript">
function nextWeek() {
var todayInMs = today.getTime();
var nextWeekInMs = todayInMs + (60 * 60 * 24 * 7 * 1000);
return new Date(nextWeekInMs);
}
</script>
</head>
<body>
<script type="text/javascript">
var today = new Date();
document.write(today);
</script>
<br>
Next week will be:
<script type="text/javascript">
document.write(nextWeek());
</script>
</body>
</html>
This is from Chapter 1-20 Of Visual Basic 2008 Recipes by Todd Herman, Allen Jones, Matthew MacDonald, and Rakesh Rajan
Public Class Person
Private m_FirstName As String
Private m_LastName As String
Public Sub New()
m_FirstName = String.Empty
m_LastName = String.Empty
End Sub
Public Property FirstName() As String
Get
Return m_FirstName
End Get
Set(ByVal value As String)
m_FirstName = value
End Set
End Property
Public Property LastName() As String
Get
Return m_LastName
End Get
Set(ByVal value As String)
m_LastName = value
End Set
End Property
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim people = New Person() {
New Person With {.FirstName = "Todd", _
.LastName = "Herman"}, _
New Person With {.FirstName = "Amy", _
.LastName = "Herman"}, _
New Person With {.FirstName = "Alaina", _
.LastName = "Herman"}, _
New Person With {.FirstName = "Aidan", _
.LastName = "Herman"}}
MessageBox.Show(people(2).FirstName)
End Sub
End Class
No comments:
Post a Comment