Saturday, February 17, 2024

Write a JavaScript code to create a pull down menu box. INTERNET CONCEPTS AND WEB DESIGN MCSL 016.

 

 INTERNET CONCEPTS AND WEB DESIGN MCSL 016

    Write a JavaScript code to create a pull down menu box.


    <!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pull-down Menu Box</title>
</head>
<body>

<select id="menu">
    <option value="" disabled selected>Select an option</option>
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
    <!-- Add more options here -->
</select>

<script>
    // Add event listener to the select element
    document.getElementById("menu").addEventListener("change", function() {
        // Get the selected value
        var selectedOption = this.value;
       
        // Display the selected value in console (You can perform other actions here)
        console.log("Selected option: " + selectedOption);
    });
</script>

</body>
</html>

No comments:

Post a Comment