Find us on Google+ Kill the code: document.getElementById
Showing posts with label document.getElementById. Show all posts
Showing posts with label document.getElementById. Show all posts

Thursday, 24 May 2012

Surfing on a html page using iframe

Preview :








Code:


<html>
   <head>
      <script type="text/javascript">
         function surf() {
            document.getElementById('web').src=document.getElementById('url').value;
         }
      </script>


   </head>
   <table>
      <tr>
         <td>
            <input type="text" id="url" /><input type="button" id="sruf" value="surf" onclick="return surf()"/>
         </td> 
      </tr>
   </table>

   <iframe height="400px" width="400px" src="http://www.killthecode.blogspot.com" id="web"> </iframe>    



</html>

Sunday, 19 February 2012

Simple Calculator in JavaScript

calc
Preview :
Code :


<html>
<head>
<title>calc</title>
</head>
<body>
<script type="text/javascript">
function add() {
var a1 = document.getElementById('n1');
var a2 = document.getElementById('n2');
document.getElementById('ans').value = parseInt(a1.value)+parseInt(a2.value);
return;
}
function sub() {
var a1 = document.getElementById('n1');
var a2 = document.getElementById('n2');
document.getElementById('ans').value = parseInt(a1.value)-parseInt(a2.value);
return;
}
function mul() {
var a1 = document.getElementById('n1');
var a2 = document.getElementById('n2');
document.getElementById('ans').value = parseInt(a1.value)*parseInt(a2.value);
return;
}
function div() {
var a1 = document.getElementById('n1');
var a2 = document.getElementById('n2');
document.getElementById('ans').value = parseInt(a1.value)/parseInt(a2.value);
return;
}
function all(id) {
if(id=='+but') add();
if(id=='-but') sub();
if(id=='*but') mul();
if(id=='/but') div();
return;
}
</script>
<table align="center">
<tr>
<td colspan="2">
<input type="text" id="n1"/>
</td>
<td colspan="2">
<input type="text" id="n2"/>
</td>
</tr>
<tr>
<td>
<input type="button" value="+" id="+but" onclick=" return add('+but')"/>
</td>
<td>
<input type="button" value="-" id="-but" onclick=" return sub('-but')"/>
</td>
<td>
<input type="button" value="*" id="*but" onclick=" return mul('*but')"/>
</td>
<td>
<input type="button" value="/" id="/but" onclick=" return div('/but')"/>
</td>
</tr>
<tr>
<td colspan="4">
<input type="text" id="ans" readonly="readonly"/>
</td>
</tr>
</table>
</body>
</html>