0% found this document useful (0 votes)
11 views

Java Script

Uploaded by

judy.nouran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Java Script

Uploaded by

judy.nouran
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Basic Concepts of JavaScript Language

JavaScript is used to develop an interactive webpage project because HTML language


isn’t enough to achieve that.
 JavaScript fundamentals:
- JavaScript commands and instructions are called Statements.
- JavaScript Statements are written within HTML tags.
- JavaScript statements are written inside <script> ..</script> tag.
- Each statement must end with a semi-colon (;) character.
- The letter case must be considered while writing JavaScript statements.
alert () statement
- it’s used for displaying a message in a dialogue box.
alert("the message"); the message must be written within double high quotations.

EX 1:
 Create a webpage that displays a dialogue box with message "welcome“
on loading :
Write the following HTML tags, and save the file with .htm extension.

<body>
<script>
alert("welcome");
</script>
</body>

Document .write(…) statement.


- it’s used for displaying text within a webpage contents.
- Document .write(“the message");
EX 2:
 Create a webpage displays "computer and information technology” text as
its content
<body>
<script>
Document .write("computer and information technology");
</script>
</body>

Calling JavaScript Code by a function


Function is JavaScript statements grouped together in named block and
performed according to call it .
• It’s implemented when an event occurs (such as button click)
To call any function write:
1- add “button”
2- add event “onclick” then the name of the function as the following
<input type=“button”onclick=“function()” value=“click here”>
To create a function:
• Write a word function and give it a suitable name
• Write a group of JavaScript statements between { … } curly brackets as a
following:
function_name() {
code to be executed
}

EX 3:
 Create a function that displays "Arab Republic of Egypt" via a message box
<script>
function country()
{
alert ("Arab republic of Egypt");
}
</script>
</body>
Textbox content manipulation

-When a button clicked, an alert box will be displayed in which the content of
the textbox can be seen

EX 4:
Note:
<html>  Give a name form1 to the <form>
<body> element (name="form1")
 Give a name t1 to the textbox
<form name="form1"> (name="t1")
<input type="text"name="t1">
<input type="button"onclick="word()"value="click me">
</form>
<script>
function word()
{
alert(form1.t1.value);
}
</script>
</body>
</html>
School book answered
questions
Complete the following statements:

1. If you want JavaScript statements to be implemented when an event occurs (such as


button click), you should use a (button)

2. (function) is JavaScript statements grouped together in a named block and performed


according to call it
Put (T) in front of the correct sentence and (F) in front of the wrong one:
1. Adding a value attribute to the button element for is called a function. (T)
2. We use a “onclick” attribute for writing a text on a button (F)
3. For reading a textbox content using JavaScript language, you should give a name to the
<form> element and give a name to the textbox (T)
4. JavaScript statement is written inside <script> (T)

You might also like