Example:
Let us take an example to built a car:
1) (Role of HTML) Firstly we need parts like : The engine, drive train, brakes, tires,steering . This is equivalent to adding webforms elements like button,radio-button,input fields etc using HTML.
2) (Role of CSS) Secondly we need to arrange the set postion of these elements,like where tires will come and where brakes. And this is equivalent to setting postions,add colors,padding,margin settings using CSS.
3) (Role of JavaScript) Now everything is arranged but now we want to start the engine by pressing “start“ button from car ,this part will be done with JavaScript i.e JavaScript will add funtionality.
JavaScript will connect the the “Start”(created using HTML and CSS) button of car with it’s engine.
- What is JavaScript ?
JavaScript is a “scripting language" that give us programming language like functionality used to develop web
applications.
JavaScript is a client-side scripting language, which means
the code is processed and manipulated by the client's web browser not on the web
server.
- JavaScript vs Java
- Do we need to install JavaScript in browers or anywhere ?
No,We need to install JavaScript anywhere.
Example of usage of JavaScript:
1)To check textbox must not be empty.
1)To check textbox must not be empty.
2)To add button on Click.
3)To Enable/Disable text-box on click.
- Embedding JavaScript in Webpage:
Basically there are three ways to embedding JavaScript in web application:
1) By Creating Separate JavaScript file then adding it to using "script" tags. (most recommended)
Example:
<script src='login.js' type='text/javascript'></script>
2) By write code under <script></script> tags under <head></head> tags.
Example:
<script>
////----javaScript Code here-----------------////
</script>
3) Withing the element. (least recommended)
Example: <button onClick="alert('hello World ! ')">Click me !</button>