Open In App

What is Scripting ?

Scripting is used to automate tasks on a website. It can respond to any specific event, like button clicks, scrolling, and form submission. It can also be used to generate dynamic content. and JavaScript is a widely used scripting language. In this article, we will learn about types of scripting, their features, benefits, applications, and steps to use them.

Types of scripting

There are two types of scripting:

  1. Client-side scripting (browser scripting)
  2. Server-Side Scripting

1. Client-side scripting (Browser Scripting)

Client-side scripting refers to the scripts that run on the user’s web browser. and JavaScript is the most common language for scripting. It is mostly supported by all browsers, and it allows dynamic scripting. It can handle user interactions like button clicks, hovers, and form submissions, and it can also reduce the load on the server as processing happens on the client side. By using client-side scripting, you can also validate the form field, access the DOM, and manipulate it to dynamically change its content.



2. Server-side scripting

Server-side scripting refers to scripts that run on the web server. and languages such as PHP, Python, Java, and Node. JS is used for server-side scripting. In server-side scripting, the script is executed before it is sent to the browser. It can handle tasks that require a database, file system, and any other server resources securely. It creates dynamic content based on user requests. You can also create an API by using server-side scripting.

Features of Browser Scripting

Benefits of Browser Scripting

Application of Scripting

Steps to use Scripting

  1. Choose a Scripting Language. Ex, JavaScript
  2. Use any code editor for writing your script. Ex, Notepad, VS Code, Sublime Text etc..
  3. Learn How to manipulate a DOM and Event Handling.
  4. Run your Script on Any Browser.

Example

In this example we are change the text GeeksForGeeks on calling a function by button click event. and after 2 second it is alerting a message.




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GeeksForGeeks</title>
</head>
<body>
    <h1>GeeksForGeeks | Browser Scripting</h1>
    <button onclick="showtext()">Say Hello</button>
    <h2 id="text">GeeksForGeeks</h2>
  
    <!-- Script tag is used to write Script  -->
    <script>
        // JavaScript code starts here
        // This Function is called when you click on "Say Hello" button.
        const showtext = () => {
            // Get the element with the id 'text'
            let text = document.getElementById('text')
              
            // Change the text content of the 'text' element
            text.innerText = "Hello"
  
            // Set a timeout to display an alert after 2 seconds
            setTimeout(() => {
                alert("Text has been changed")
            }, 2000)
        
    </script>
</body>
</html>

Output

Conclusion

Scripting plays an vital role to guiding browser on how to respond to events. And JavaScript is the popular and broadly used language for scripting. By using scripting you can dynamically change content by using DOM, event handling and AJAX.


Article Tags :