Monday, March 30, 2026

wtp-oldppr-solution

 Here is an easy GTU-style answer with examples πŸ‘‡


Q.Blur, Onfocus and Onclick Events in JavaScript

In JavaScript, events are actions that happen when the user interacts with a web page such as clicking a button, entering text, or leaving a field.


1) onfocus Event

The onfocus event occurs when the user clicks inside a textbox or form field.

Example:

<html>
<body>
<input type="text" onfocus="changeColor(this)">

<script>
function changeColor(x){
    x.style.background = "yellow";
}
</script>
</body>
</html>

Explanation:
When the cursor enters the textbox, its background becomes yellow.


2) onblur Event

The onblur event occurs when the user leaves a textbox or input field.

Example:

<html>
<body>
<input type="text" onblur="makeUpper(this)">

<script>
function makeUpper(x){
    x.value = x.value.toUpperCase();
}
</script>
</body>
</html>

Explanation:
When the user moves out of the textbox, the text is converted to uppercase.


3) onclick Event

The onclick event occurs when the user clicks a button or any clickable element.

Example:

<html>
<body>
<button onclick="showMsg()">Click Me</button>

<script>
function showMsg(){
    alert("Button Clicked!");
}
</script>
</body>
</html>

Explanation:
When the button is clicked, an alert message is shown.


Conclusion (4 short points as you like)

  1. onfocus – activates when cursor enters a field.

  2. onblur – activates when cursor leaves a field.

  3. onclick – activates when user clicks a button.

  4. These events make web pages interactive.


If you want, I can also give one combined program for exam πŸ‘


Here is your answer in easy English, GTU style, and with your question 😊
(As you like: clear + simple)


Q. Discuss Keyboard Events in JavaScript with example.

Definition

Keyboard events in JavaScript are used to detect when a user presses, releases, or types a key on the keyboard.

They help us take action when the user types something in an input box or presses a key.


Types of Keyboard Events

EventDescription
keydownOccurs when a key is pressed down
keypressOccurs when a character key is pressed (old event)
keyupOccurs when a key is released

Why Keyboard Events are used (4 points)

  1. To detect which key the user presses.

  2. To validate user input while typing.

  3. To block unwanted keys (like numbers in name field).

  4. To create shortcut keys and games.


Example: Keyboard Event in JavaScript

<!DOCTYPE html>
<html>
<head>
    <title>Keyboard Event Example</title>
    <script>
        function showKey(event) {
            document.getElementById("output").innerHTML =
            "You pressed: " + event.key;
        }
    </script>
</head>
<body>

    <h3>Type something:</h3>
    <input type="text" onkeydown="showKey(event)">
    <p id="output"></p>

</body>
</html>

Output

When you press any key in the textbox, it shows the key name on the screen.


Conclusion

Keyboard events make a webpage interactive by responding to user key actions like typing, pressing, and releasing keys.


If you want, I can give 1-mark version or very short exam answer πŸ‘


Here is AngularJS Form Validation in easy English, GTU style, with your question and a simple example.


Q. Explain AngularJS Form Validation with Example.

Definition

AngularJS Form Validation is used to check user input in a form before submitting it.
It automatically shows errors when the user enters wrong or empty data.


Why Form Validation is used (4 short points)

  1. Prevents wrong data from being submitted
  2. Improves user experience
  3. Saves server time
  4. Ensures correct input format

Common AngularJS Validation Directives

Directive Use
required Field must not be empty
ng-minlength Minimum length
ng-maxlength Maximum length
type="email" Valid email
$touched Field is clicked
$invalid Input is wrong

Example: AngularJS Form Validation

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>

<body ng-controller="myCtrl">

<form name="myForm">

Name:
<input type="text" name="uname" ng-model="user.name" required>
<span style="color:red" 
ng-show="myForm.uname.$touched && myForm.uname.$invalid">
Name is required
</span>

<br><br>

Email:
<input type="email" name="uemail" ng-model="user.email" required>
<span style="color:red"
ng-show="myForm.uemail.$touched && myForm.uemail.$invalid">
Enter valid email
</span>

<br><br>

<button ng-disabled="myForm.$invalid">Submit</button>

</form>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {});
</script>

</body>
</html>

How it works (4 easy steps)

  1. required checks empty input
  2. $touched checks user clicked field
  3. $invalid checks wrong input
  4. Button disabled if form is invalid

Conclusion

AngularJS Form Validation automatically checks user input and shows error messages before form submission.


If you want, I can give short 1-mark version, MCQ, or Viva notes πŸ˜„

Here is Authentication and Authorization in Laravel in easy English, GTU style, with short 4-point format and examples.


Q. Explain Authentication and Authorization in Laravel.


πŸ” Authentication in Laravel

Definition

Authentication in Laravel is used to check user login using email & password before giving access.

4 Points

  1. Verifies user identity
  2. Uses login system
  3. Protects private routes
  4. Works with sessions/tokens

Example (Route Protection)

Route::get('/dashboard', function () {
   return view('dashboard');
})->middleware('auth');

πŸ›‘️ Authorization in Laravel

Definition

Authorization in Laravel is used to check user permission/role to access a page or perform an action.

4 Points

  1. Controls user permissions
  2. Uses Gates & Policies
  3. Restricts sensitive actions
  4. Works after authentication

Example using Gate

Step 1: Define Gate (AuthServiceProvider)

Gate::define('isAdmin', function ($user) {
    return $user->role == 'admin';
});

Step 2: Use in Blade

@can('isAdmin')
   <button>Delete User</button>
@endcan

Difference Table

Authentication Authorization
Who you are What you can do
Login Permission
Uses auth Uses Gate, Policy

Conclusion

Laravel uses Authentication to verify users and Authorization to control access.


If you want MCQs, 1-mark, or API version (Sanctum), tell me 😊

Here is a JavaScript function to calculate factorial in easy English, simple and short.


Q. Write a JavaScript function to calculate factorial of a number.

Definition

Factorial of a number (n!) means:
n! = n × (n-1) × (n-2) × ... × 1


JavaScript Function

<script>
function factorial(num) {
    let fact = 1;

    for (let i = 1; i <= num; i++) {
        fact = fact * i;
    }

    return fact;
}

// Example
let result = factorial(5);
document.write("Factorial is: " + result);
</script>

Output

Factorial is: 120

4 Easy Points

  1. Function name is factorial()
  2. Loop multiplies numbers
  3. Returns factorial value
  4. Called with factorial(5)

If you want recursive version or user input version, tell me πŸ˜„

Here is PHP Control Structures – Theory + Example, in easy English, GTU style, with short points.


Q. Explain PHP Control Structures with Example.

Definition

Control Structures in PHP are used to control the flow of program execution.
They decide which statement runs and how many times it runs.


Types of PHP Control Structures

1. Conditional Control Structures

Used for decision making.

Types: if, if-else, if-else-if, switch

<?php
$a = 10;
if($a > 5){
   echo "Greater than 5";
}
?>

2. Looping Control Structures

Used to repeat a block of code.

Types: for, while, do-while, foreach

<?php
for($i=1; $i<=5; $i++){
   echo $i . "<br>";
}
?>

3. Jumping Control Structures

Used to change normal program flow.

Types: break, continue, return

<?php
for($i=1; $i<=5; $i++){
   if($i == 3) break;
   echo $i;
}
?>

4. Exception Handling

Used to handle errors.

Types: try, catch, finally

<?php
try {
   throw new Exception("Error found!");
}
catch(Exception $e){
   echo $e->getMessage();
}
?>

Conclusion

PHP control structures help in decision making, looping, and handling errors in a program.


If you want short 1-mark, MCQs, or diagram, tell me 😊

Here is the PHP program to find the largest number among three using user input, in easy English.


PHP Script: Largest Number Among Three (User Input)

<!DOCTYPE html>
<html>
<body>

<form method="post">
    Enter First Number: <input type="number" name="a"><br><br>
    Enter Second Number: <input type="number" name="b"><br><br>
    Enter Third Number: <input type="number" name="c"><br><br>
    <input type="submit" name="submit" value="Find Largest">
</form>

<?php
if(isset($_POST['submit'])) {
    $a = $_POST['a'];
    $b = $_POST['b'];
    $c = $_POST['c'];

    if($a > $b && $a > $c) {
        echo "Largest number is: $a";
    }
    else if($b > $a && $b > $c) {
        echo "Largest number is: $b";
    }
    else {
        echo "Largest number is: $c";
    }
}
?>
</body>
</html>

How it works (4 short points)

  1. User enters 3 numbers
  2. Data sent using POST
  3. if-else compares values
  4. Displays the largest number

If you want small version without form or same with validation, tell me πŸ˜„


No comments:

Post a Comment

Personality Development[imp]

Short Questions Answers: Q.1 Define Personality. Personality is the combination of a person’s thoughts, feelings, and behavior that makes th...