html ক্যোয়ারীর জন্য প্রসঙ্গ অনুসারে বাছাই করা পোস্ট দেখানো হচ্ছে৷ তারিখ অনুসারে বাছাই করুন সব পোস্ট দেখান
html ক্যোয়ারীর জন্য প্রসঙ্গ অনুসারে বাছাই করা পোস্ট দেখানো হচ্ছে৷ তারিখ অনুসারে বাছাই করুন সব পোস্ট দেখান

JavaScript Arithmetic Operators and Operands

JavaScript Arithmetic Operators:

Arithmetic operators perform operation on numbers (literals or variables).
  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Exponentiation (ES2016) (**)
  • Division (/)
  • Modulus (Remainder) (%)
  • Increment (++)
  • Decrement (--)
A typical arithmetic operation operates on two numbers.
The two numbers can be literals:

<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 100 + 10; 
document.getElementById("example").innerHTML = a; 
</script>

Result:
110
or variables with value:
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var x = 100; 
var y = 10; 
var z = x + y; 
document.getElementById("example").innerHTML = z; 
</script>

Result:
110
or directly with expressions:
<!DOCTYPE html> 
<html> 
<body> 
<p id="example">
</p> 
</body> 
</html>
<script> 
var a = 3; 
var b = (10 + 5) * a; 
document.getElementById("example").innerHTML = b; 
</script> 

Result:
45

Operators and Operands:

The numbers used in an arithmetic operation are called operands. Which Operation to be performed between the two operands is defined by an operator.
a + b // here a, b Operands and + Operator.
Adding Operator (+):
<!DOCTYPE html> 
<html> 
<body> 
<h2>Adding Operator (+)</h2> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 10; 
var b = 2; 
var c = a + b; 
document.getElementById("example").innerHTML = c; 
</script>
Subtraction Operator (-):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 15; 
var b = 10; 
var c = a - b; 
document.getElementById("example").innerHTML = c; 
</script>
Multiplication Operator (*):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 15; 
var b = 5; 
var c = a * b; 
document.getElementById("example").innerHTML = c; 
</script>
Division Operator (/):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 15; 
var b = 3; 
var c = a / b; 
document.getElementById("example").innerHTML = c; 
</script>
Modulus Operator (%):
It returns the division remainder.
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 7; 
var b = 2; 
var c = a % b; 
document.getElementById("example").innerHTML = c; 
</script>

Result:
1
Increment Operator (++):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 10; 
a++; 
var b = a; 
document.getElementById("example").innerHTML = b; 
</script>

Result:
11
Decrement Operator (--):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 10; 
a--; 
var b = a; 
document.getElementById("example").innerHTML = b; 
</script>
Exponentiation Operator (**):
(**) is called exponentiation operator that raises the first operand to the power of the second operand.
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 10; 
document.getElementById("example").innerHTML = a ** 2; 
</script>

Result:
100
Exponentiation Operator (**) produces the same result as Math.pow(x,y):
<!DOCTYPE html> 
<html> 
<body> 
<p id="example"></p> 
</body> 
</html> 
<script> 
var a = 10; 
document.getElementById("example").innerHTML = Math.pow(a,2); 
</script>

Result:
100

Project Source Code:
<!DOCTYPE html> 
<html> 
<body> 
<h2>JavaScript Operators</h2> 
<p><b style="color: red"> Arithmetic operators used by JavaScript ( + - * / )</b> to compute values (just like algebra).</p> 
<p id="example"></p> 
</body> 
</html> 
<script type="text/javascript"> 
document.getElementById("example").innerHTML = (6 - 3) / 2;// any arithmetical operation can be done using js arithmetic operators 
</script>
Read More

Add Remove Input Fields Dynamically using Javascript & Html

What is Javascript Dynamic fields?
When the input field will not be static and we can change the number of input field by clicking the button then it is called the dynamic fields.

Why use Javascript Dynamic fields?
In our application, sometimes we need to add more details of the products. In that case, we use add more button so that we can easily add the more details about the product.

For example, when we going to add a medicine name "PARACETAMOL" in the system. we have to think about the variation of this product. Because PARACETAMOL has different variation. In that case we need to use dynamic input field option. So that, we can easily add this multiple variation product in the system.

That's the main motive to use javascript dynamic fields in the application.

How looks Javascript Dynamic fields?
In the below, there is a demo of Javascript dynamic fields. It looks exactly like the following. 
In this demo, i have used two button. 
  1. Minus Mark Button
  2. Plus Mark Button
Once you click on "Plus Mark Button" then one input field row will be automatically added in the system.

But if you click on "Minus Mark Button" then one input field row will be automatically Removed from the system.

Preview Example:

Dynamically input field using javascript

Way to create dynamic Add/Remove input field?
Today, I'm going to show How to create add/remove input fields dynamically with JavaScript in laravel 5.8 project.

We can easily create Add more fields and Remove group of input fields using JavaScript in laravel. We will create javascript dynamic fields with bootstrap 4 and JavaScript in laravel project.

Use laravel validation for add more input fields. You can add more multiple input fields like sometimes we need to add same information add multiple time with same form input. That's why we will create table row with input fields and add add more button so when you click on that button then it will append new row with input fields.

There is the Code Source. By using this code you can easily create Dynamic Add/Remove Input Fields. You can also watch the following video. In this video i have shown how to use this code properly.

Source Code:

<!DOCTYPE html> 
<html> 
<title>Page Title</title> 
<body> 
<?php $row_num=1;?> 
<table class="table table-responsive"> 
<thead> 
<tr> 
<th>Info.</th> 
<th>Medicine Name</th> 
<th>Quantity</th> 
<th>Unit/Price</th> 
<th>Total</th> 
<th>Action</th> 
</tr> 
</thead>
<tbody class="row_container"> 
<tr id="div_{{$row_num}}"> 
<td> 
<a href="javascript:0" class="btn btn-warning"><i class="fa fa-info-circle"></i></a> 
</td> 
<td>
<input type="text" name="medicine_name" class="form-control" placeholder="Medicine Name"> 
</td> 
<td> 
<input type="text" name="quantity" class="form-control" placeholder="Quantity"> 
</td>
<td> 
<input type="text" name="unit_price" class="form-control" placeholder="Unit Price"> 
</td> 
<td> 
<input type="text" name="total" class="form-control" placeholder="Total">
</td>
<td> 
<a href="javascript:0" class="btn btn-danger"><i class="fa fa-minus" onclick="$('#div_{{$row_num}}').remove();"></i></a> 
</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>

<script type="text/javascript"> 
var RowNum = '{{$row_num}}'; 
function addrow(){ 
RowNum++; 
var html = ""; 
html += '<tr id="div_'+RowNum+'">'; 
html +='<td>'; 
html +='<a href="javascript:0" class="btn btn-warning"><i class="fa fa-info-circle"></i></a>';
html +='</td>';
html +='<td>'; 
html +='<input type="text" name="medicine_name" class="form-control" placeholder="Medicine Name">'; 
html +='</td>'; 
html +='<td>';
html +='<input type="text" name="quantity" class="form-control" placeholder="Quantity">'; 
html +='</td>'; 
html +='<td>'; 
html +='<input type="text" name="unit_price" class="form-control" placeholder="Unit Price">'; 
html +='</td>'; 
html +='<td>';
html +='<input type="text" name="total" class="form-control" placeholder="Total">'; 
html +='</td>'; 
html +='<td>'; 
html +='<a href="javascript:0" class="btn btn-danger"><i class="fa fa-minus"  onclick="$(\'#div_'+RowNum+'\').remove();"></i></a>'; 
html +='</td>'; 
html +='</tr>';
$('.row_container').append(html);}
</script>
Here is the video to create dynamic Add/Remove input field in Laravel using JavaScript. Thank you.
Read More