Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Thursday, December 26, 2013

Display Stars using javascript

a. Take a positive integer value from the respondent as below fig. and Display Star Diamond.
b. Validate above form field
c. ON VALIDATION DISPLAY PROPER USER FRIENDLY MESSAGE TO USER.
d. Try to design a good looking html page with proper alignment..
e. You are only allowed to use HTML for design the page and JavaScript for scripting logic.



<html>
<head>
<script type="text/javascript">
function display(){
var reg=/^[0-9]$/;
var content = document.getElementById("top").innerHTML;
var divText="<br><fieldset style='background-color:green;color: #123abc;width: 400px;'><legend>"+"Star Diamond"+"</legend><fieldset style='background-color:yellow;color: #123546;width: 75px;'>";
var input=document.getElementById("tex").value*1;
var space=input-2;
var line=(input+1)/2;
;
if(input==""){
alert("Please enter Number");
return false;
}
if((input%2)==0)
{
alert("Please enter Number");
return false;
}
for(var i=0; i<line;i++)
{
for (var c = 1 ; c < space; c++ )
divText=divText+"&nbsp";
space--;
for (var d = 1 ; d <=2*i+1 ; d++ )
divText=divText+"*";
divText=divText+"<br>";
}
var down=(input-1)/2;
var spa=1;
for(var r=down; r>0; r--)
{
for(var sp=spa; sp>=1; sp--)
divText=divText+"&nbsp";
spa++;
for(var m=1; m<=2*r-1; m++)
divText=divText+"*";
divText=divText+"<br>";
}
divText=divText+"</fieldset>";
content=content+divText;
document.getElementById("top").innerHTML=content;
return true;
}
</script>
</head>
<body><center><form id="1">
<div id="top">
<fieldset style="background-color:orange;color: #123abc; width: 400px;">
<legend style="background-color:green;color: #ff0000; font-family: verdana; font-size: 14pt;">DISPLAY</legend>
<div>Enter Number you want:<input type="text" id="tex" value=""><input type="button" id="dis" value="Display" onclick="return display()"></div>
</fieldset>
</div>
</form></center>
</body>
</html>

Monday, November 18, 2013

Find Number of days between two given dates in Javascript

My question is Find number of days between the two given dates by using javascript. See below code, copy and paste the code into your html page in head tag.

<script>
function   DiffInDays(startDate, endDate){
      startDate = new Date(startDate);
      endDate = new Date(endDate);
      if(endtDate.getTime() > startDate.getTime())
      {
             var diffDays = endDate.getDate() - startDate.getDate();
             alert("Difference in Days :"+diffDays/86400000);// MilliSeconds for one day is 1000*60*60*24
       }
       else  if(endtDate.getTime() == startDate.getTime()){
             alert("StartDate and endDate are equal");
       }
       
}
</script>

Friday, August 9, 2013

Delete given character from text using javascript

a. Design a HTML page as below
b. You can take any sentence like the above diagram. Take only character from the user and remove the character from the given sentence and after clicking on “Click” button, display the sentence again after removing the character as below.
c. Validate for only characters.
d. Design a good looking HTML page.



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script>
function clickCha(){
var inn=document.getElementById('1').innerHTML;

while(inn.search(document.getElementById('cha').value)!=-1){
inn=inn.replace(document.getElementById('cha').value,"");

}
var content=document.getElementById('tab').innerHTML;
content=content+inn;
document.getElementById('tab').innerHTML=content;
return true;

}
</script>
<body><center>
<form><fieldset style='border:solid;' id='tab'>
<p id='1'>We at Nacre have created an idea work environment wherenin every Nacrean adheres to set of rules and regulations practiced in the corporate world.This exposes team to corporate culture,leading to inculcation of professionalisam,integrity,time manangement,efficient delegation of work and optimal working strategies both individually and within teams.Nacreans adhere to the following rules and regulations.</p>

Enter a Character:
<input type='text' name='tex' id='cha' value=''>
<input type='button' id='cli' value='click'
onclick='return clickCha()'><br>
</fieldset>
</form></center>
</body>
</html>

Tuesday, July 16, 2013

Prime Numbers in javascript

<HTML>
<HEAD>
<TITLE> Prime Number </TITLE>
</HEAD>
<script>
var inum=prompt("Enter a Value");
var a=new Array();
var val=0;
for(var ind = 1;ind<=inum;ind++){
count = 0;
for(i=2;i<=ind/2;i++){
if(ind%i==0){
count++;
break;
}
}
if(count==0 && ind!= 1){
a[val]=ind;
val++;
}
}
var indVal=9;
var inc=0;
while(inc<a.length)
{
inc++;
document.write("<font color='#"+ Math.floor(Math.random() * 16777215).toString(16)+"'>"+a[indVal]+"&nbsp&nbsp</font>");
indVal--;
if(inc%10==0)
{
document.write("<br>");
indVal=inc+9;
}
if(indVal>a.length)
{
var temp=indVal-a.length;
indVal=indVal-temp-1;
}
}
</script>
<body>
</body>
</html>

ImageSlideShow

Write a JavaScript program for ImageSlideShow?

Conditions:
a) Create a html page that has 10 images in it.
b) Create a slideshow that displays images with the gap of 2 seconds.
c) There should be counter on the screen that displays the total number of images, images already shown
and images left in the queue should also be shown as a status.
d) Display page content in the middle of the page in proper alignment
e) Try to prepare a good looking html page .
f) You are only allowed to use html for design the page and javascript for scripting logic.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Slide Show</title>
<script>
var ind=0;
var pre=0;
function valid(){
setTimeout(function(){slide()},1000);
}
function slide()
{
if(ind<8){
var imgArr=["Blue hills.jpg","Sunset.jpg","Water lilies.jpg","Winter.jpg","Bluei.jpg","Bluei1.jpg","Bluei2.jpg","Bluei3.jpg"];
var content="<img src='"+imgArr[ind]+"' width='200' height='200'>";
document.getElementById('pp').innerHTML=content;
    document.getElementById('pre').value=ind;
    document.getElementById('now').value=ind+1;
    document.getElementById('next').value=imgArr.length-ind-1;
    ind=ind+1;
    
    valid();
    }
}

</script>

</head>
<body>
<form><div><p id='pp'><br><input type='button' id='sta' value='Start' onclick='return valid()'></p><br>
Previous <input type='text' id='pre'>
Present:<input type='text' id='now'>
Remain:<input type='text' id='next'>

</div></form>

</body>
</html>

Monday, July 15, 2013

RegistrationForm


a. Design a HTML page as below fig. 
b. Validate above form field 
i. Name Field should not be empty. 
ii. Validate Name field for only characters and special symbols i.e.(A-Z a-z _ . ). 
iii. Validate Gender: At least choose one of Gender. 
iv. Above validation should happen on form submit, i.e. ‘Onclick’ on Submit Button 
c. Display form content in the middle of the page with proper alignment. 
d. Try to design a good looking html page. 
e. You are only allowed to use HTML for design the page and JavaScript for scripting logic.


<html>
<head>
</head>
<script>
function checkForm()
{
var reg=/^[a-zA-z._]+$/;
var user_name=document.getElementById("userName").value;
var gen=document.getElementsByName('gender');
var qualification=document.getElementsByName('qua');
if(user_name=='')
{
alert("Please Enter Your Name");
document.getElementById('userName').focus;
return false;
}
//checking userName withregularExpression
if(!user_name.match(reg))
{
alert("please enter alphabitical and symbols");
}
//checking options are selected or not
if (document.getElementById('male').checked == false && document.getElementById('female').checked == false)
{
alert("Please select gender");
}
for(var ind=0;ind<qualification.length;ind++)
{
if(qualification[ind].checked==true)
return true;
}
return false;
alert("Your name is "+user_name);
return true;
}
</script>
<body><center><form name="regForm" id="res" onsubmit="return checkForm()">
<div id="form" style="width:350px; background-color:green">
<fieldset>
<legend style="BackGround-color:blue;color:yellow;font-weight:bold;">RegistrationForm</legend>
<table>
<tr>
<td>Name:<span style="color:red; ">*</span> <input type="text" name="userName" value="" style="border: 5px; bordercolor:red"></td></tr>
<tr>
<td>Gender:<b style="color:red">*</b>&nbsp<td bgcolor="red"><input type="radio" name="gender" id="male" value="Male">Male <input type="radio" name="gender" id="female" value="Female">Female </td>
</tr>
<tr>
<td>Qualification:<b style="color:red">*</b></td><td bgcolor="yellow"><input type="radio" name="qua" id="bca" value="Male">BCA <input type="radio" name="qua" id="bsc" value="bsc">BSc</br><input type="radio" name="qua" id="bca" value="Mca">MCA <input type="radio" name="qua" id="mtech" value="mtech">Mtech </td>
</tr>
<tr>
<td colsapn="2" align="center"><input type="submit" name="reges" id="regist" value="Submit"></td>
</tr>
</table>
</fieldset>
</div></form>
</center></body>
</html>

Reverse String

a. Create a HTML page with a text box and a button. 
b. Take a string as input from user and count different types of characters in given string and print and also print the reverse of the string in same page. 
c. Validate for m fields for Empty - 
i. Above validation should happen on button click. 
ii. ON VALIDATION DISPLAY PROPER USER FRIENDLY MESSAGE TO USER. 
d. For example: “apple” would be 
a=1 
p=2 
l=1 and 
e=1 
Reverse: 
apple -> elppa 
e. Display page content in the middle of the page with proper alignment. 
f. Try to design a good looking html page. 

g. You are only allowed to use HTML for design the page and JavaScript for scripting logic. 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<script>
function strReverse()
{
var input=document.getElementById('text1').value.trim();
var content=document.getElementById('stringt');
var newTable="<tr><td>";
var cha=new Array();
var reverse=[];
var leng=input.length-1;
var stri='';
//reverse.length=input.length;
var reg=/^[a-zA-Z._]+$/;
if(!reg.test(input))
{
alert("Please enter String");
return false;
}
cha.length=input.length;
var count;
for(var index=0;index<input.length;index++)
{
count=1;
reverse[leng-index]=input[index];
for(var i=0;i<input.length;i++)
{
if(index!=i&&input[index]==input[i])
{
count++;
}
}
if(input[index]==input[index-1]){}
else{
cha[index]=input[index]+'='+count;
newTable=newTable+cha[index]+"</td></tr><tr><td>";
}
}
for(var c=0;c<leng+1;c++)
{
stri=stri+reverse[c];
}
newTable=newTable+"<tr><td>"+stri+"</td></td></table>";
content.innerHTML=newTable;
return true;
}
</script>
<BODY><center>
<form id='form' onsubmit='return strReverse()'>
<div id='con' style="width:250px; background-color:green">Enter Your Name:<input type='text' name='str' id='text1' value=''><br>
<input type='button' name='sbutton' id='strButton' value='submit' onclick='return strReverse()'><table id='stringt' style="width:250px; background-color:red; align:middle"></table>
</div>
</form></center>
</BODY>
</HTML>