Forum : Plz check out the code..Its not working...
Brief description  about Online courses   join in Online courses
View Sweety  Agarwal 's Profile

Plz check out the code..Its not working...

<html>
<head>
<title>Variable Assignment</title>
<style type="text/css">
h1
{
font-size:30px;
font-family:"Comic Sans MS", cursive;
text-align:center;
color:#4AA02C;
}

body
{
background-color:#FDD017;
}

td
{
font-size:20px;
color:#7E2217;
}

.padding
{
padding-left:30px;
}

.float
{
float:left;
}
#float
{
float: right;
}
</style>

<script type="text/javascript">
function calculate()
{
a=document.form1.first.value;
b=document.form1.second.value;
c=(a b);
document.form1.result.value=c;
}
function rev()
{
a=document.form1.first.value
document.form1.afterreverse.value=a.reverse()
}

function adding()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a b);
document.form2.total.value=c;
}

function sub()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a-b);
document.form2.total.value=c;
}

function mul()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a*b);
document.form2.total.value=c;
}

function divi()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a/b);
document.form2.total.value=c;
}
</script>
</head>
<body>
<h1><u>Variable Assignment</u></h1><br/><br/>
<form name="form1">
<table class="float" border=0>
<tr>
<td>String1:</td>
<td class="padding"> <input type="text" name="first" /></td>
<tr>
<td>String2:</td>
<td class="padding"><input type="text" name="second" /></td>
</tr>
<tr>
<td>Result: </td>
<td class="padding"><input type="text" name="result" /></td>
</tr>
<tr align=center>
<td><input type="button" value="Concatenate" onClick=calculate() /></td>
<input type="button" value="Reverse" onClick=rev() />
<input type="text" name="afterreverse"/>
</tr>
</table>
</form>

<form name="form2">
<table id="float">
<tr>
<td>Enter First Number:</td>
<td class="padding"> <input type="text" name="firstname" /></td>
<tr>
<td>Enter Second Number:</td>
<td class="padding"><input type="text" name="secondname" /></td>
</tr>
<tr>
<td>Total: </td>
<td class="padding"><input type="text" name="total" /></td>
</tr>
<tr>
<td align="center" colspan=2>
<input type="button" value=" " onClick=adding()/>
<input type="button" value="-" onClick=sub() />
<input type="button" value="*" onClick=mul()/>
<input type="button" value="%" onClick=divi()/>
</td>
</tr>
</table>
</form>
</body>
</html>
Asked by Sweety Agarwal | Oct 11, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Sweety,

<html>
<head>
<title>Variable Assignment</title>
<style type="text/css">
h1
{
font-size:30px;
font-family:"Comic Sans MS", cursive;
text-align:center;
color:#4AA02C;
}

body
{
background-color:#FDD017;
}

td
{
font-size:20px;
color:#7E2217;
}

.padding
{
padding-left:30px;
}

.float
{
float:left;
}
#float
{
float: right;
}
</style>

<script type="text/javascript">
function calculate()
{
a=document.form1.firsty.value;
b=document.form1.secondy.value;
c=(a+b);
document.form1.result.value=c;
}

function reverse_string(str){
var stri = "";
var alen = str.length;
for (var i = alen ; i > 0 ; i--){
stri += str.charAt(i-1)
}
return stri;
}


function rev()
{
a=document.form1.firsty.value;
b= reverse_string(a);
document.form1.afterreverse.value= reverse_string(a);

if(a==b)
{
alert("Palindrome");
}
else
{
alert("Not a palindrome");
}

}

function adding()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a+b);
document.form2.total.value=c;
}

function sub()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a-b);
document.form2.total.value=c;
}

function mul()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a*b);
document.form2.total.value=c;
}

function divi()
{
a=document.form2.firstname.value;
b=document.form2.secondname.value;
a=Number(a);
b=Number(b);
c=(a/b);
document.form2.total.value=c;
}
</script>
</head>
<body>
<h1><u>Variable Assignment</u></h1><br/><br/>
<form name="form1">
<table class="float" border=0>
<tr>
<td>String1:</td>
<td class="padding"> <input type="text" name="firsty" /></td>
<tr>
<td>String2:</td>
<td class="padding"><input type="text" name="secondy" /></td>
</tr>
<tr>
<td>Result: </td>
<td class="padding"><input type="text" name="result" /></td>
</tr>
<tr align=center>
<td><input type="button" value="Concatenate" onClick=calculate() /></td>
<input type="button" value="Reverse" onClick=rev() />
<input type="text" name="afterreverse" />
</tr>
</table>
</form>

<form name="form2">
<table id="float">
<tr>
<td>Enter First Number:</td>
<td class="padding"> <input type="text" name="firstname" /></td>
<tr>
<td>Enter Second Number:</td>
<td class="padding"><input type="text" name="secondname" /></td>
</tr>
<tr>
<td>Total: </td>
<td class="padding"><input type="text" name="total" /></td>
</tr>
<tr>
<td align="center" colspan=2>
<input type="button" value=" " onClick=adding() />
<input type="button" value="-" onClick=sub() />
<input type="button" value="*" onClick=mul() />
<input type="button" value="%" onClick=divi() />
</td>
</tr>
</table>
</form>
</body>
</html>


Check it now.

Regards,
Vishwanath
Oct 11, 2010