Showing posts with label product of two numbers in javascript. Show all posts
Showing posts with label product of two numbers in javascript. Show all posts

Tuesday, December 24, 2019

Product of Two Numbers in JavaScript

I wrote this program using JavaScript to ask the user to give two numbers and then the program will compute the product of two numbers and display the results using an alert dialog box in JavaScript.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com
My programming website is http://www.jakerpomperada.blogspot.com

I am also a book author you can purchase my books on computer programming and information technology in the following links below.

https://www.mindshaperspublishing.com/
https://www.unlimitedbooksph.com/



Sample Program Output


Program Listing

index.html

<html>
  <head>
   <title>Product of Two Numbers in JavaScript</title>
  </head>
  <style>
      body {
       font-family: arial;
       font-size: 20px;
       font-weight: bold;
      }
   </style>
  <body>
 
<script>
function product(){
var num1=document.form.text1.value;
var num2=document.form.text2.value;
var sum=Number(num1)*Number(num2);
alert("The product between " + num1 + " and " + num2 + " is " + sum + ".");
}
</script>
<form name="form"><br>
<h4>Product of Two Numbers in JavaScript</h4>
<table>
<tr>
<td>Enter First Number:</td>
<td><input type="text" name="text1"></td>
</tr>
<tr>
<td>Enter Second Number:</td>
<td><input type="text" name="text2"></td>
</tr>
<tr>
<tr></tr><tr></tr>
<td><input type="button" value="Solve For Product" onclick="product();"></td>
</tr>
</table>
</body>
</html>


Saturday, March 11, 2017

Product of Two Numbers in PHP and AJAX

Hi there in this article I would like to share with you how to you AJAX and PHP together to accept two numbers from the user and then our program will compute the product of the two numbers. The code is written in PHP, JavaScript and AJAX. It is very simple to understand and follow. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.








Sample Program Output


Program Listing

index.php

<html>
<head>
<title> Product of Two Numbers Using PHP and AJAX </title>
</head>
<script language="javascript" src="ajax.js">
</script>
<body>
<style>
body {
background-color:lightgreen;
font-family:arial;
font:12px;
}
</style>
<br>
<h3> Product of Two Numbers Using PHP and AJAX</h3>
<script>
function clear_all()
{    
   document.getElementById("num1").value= "";
   document.getElementById("num2").value= "";
}
</script>
<form action="javascript:product(document.getElementById('frm'));" name="frm" id="frm">
<table>
<tr>
<td>First Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num1" type="text" autofocus required/></td>
</tr>
<tr>
<td>Second Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num2" type="text" required/></td>
</tr>
<tr>
<td colspan="2">
<br>
<input type="submit" name="button" value="Solve">
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="submit" name="button" value="Clear" onClick="clear_all();">
</td>
</tr>
</table>
</form>
<div name="txt" id="txt"></div>
</body>
</html> 

ajax.js


function product(obj)
{

var XMLHttpRequestObject=false;
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}

var str1= "num1=" + document.getElementById("num1").value;
var str2="&num2=" +document.getElementById("num2").value;

XMLHttpRequestObject.onreadystatechange = show;
XMLHttpRequestObject.open('POST', 'value.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

XMLHttpRequestObject.send(str1+str2);

function show()
{
if (XMLHttpRequestObject.readyState == 4)
{
if (XMLHttpRequestObject.status == 200)
{
result = XMLHttpRequestObject.responseText;
document.getElementById('txt').innerHTML = result;
}
}
}



value.php

<?php
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$num3=$num1*$num2;
echo "The product of $num1 and $num2 is $num3.";
?>