Wednesday 27 November 2013

Logic to Find Trim Prime Number in JS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var num = document.getElementById("txtNum").value;
            var regx = /^[1-9][0-9]*$/;
            var checkNum = regx.test(num);
            var arr = new Array();
            var count=0,count2=0,store=0;
            if (checkNum == null || checkNum == "") {
                alert("plz enter only and any no..");
            }
            else {
                alert("Enter Successfully");
            }

            for (var i = 2; i <= num; i++) {
                count = 0;
                for (var j = 2; j <= i; j++) {
                    if (i % j == 0) {
                        count++;

                    }

                }
                if (count == 1) {
                    arr[store] = i;
                    store++;
                    count2++;

                }
             
            }
            document.write("Trim Prime No's are..<br/>");
            for (var k = 0; k <= count2; k++) {
                if ((arr[k + 1] - arr[k]) == 2) {
                 
                    document.write("("+arr[k] + "," + arr[k+1]+")" + "<br/>");
                }
            }

     }
         
 </script>
</head>
<body>
<input id="txtNum" type="text" placeholder="Enter Any No.." />
<input id="btnSubmit" type="button" value="Submit" onclick="f1()" />
</body>
</html>

Logic to Find Multiplication of Any Number and Any Range in JS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var arr = new Array();
            var count = 0;
       
            var multipleno = document.getElementById("txtMultipleNo").value;
            var regxMultipleno = /^[1-9]$/;
            var checkMultipleno = regxMultipleno.test(multipleno);
         
         
            if (checkMultipleno == "" || checkMultipleno == null) {

                alert("Enter only Nos..");
                return false;
             
            }
            else {
                alert("Entered Successfully");

            }
         
            var range = document.getElementById("txtRange").value;
            var regxRange = /^[1-9][0-9]*$/;
            var checkRange = regxRange.test(range);

            if (checkRange == "" || checkRange == null) {

                alert("Enter only Nos..");
                return false;
             
            }
            else {

                alert("Entered Successfully");

            }

            for (var i = 1; i <= range; i++) {
                if ( i% multipleno == 0) {
                    arr[count] = i;

                    count++;
                }
            }
            document.write("Multiple of " + multipleno + "'s are->");
            for (var j = 0; j <= count-1; j++) {
             
                document.write("<br/>" + arr[j]);
            }

        }
        alert("hi");
    </script>
</head>
<body>
Multilpe No : <input id="txtMultipleNo" type="text" />
    <br/>
Range Upto  : <input id="txtRange" type="text" />
<input id="btnSubmit" type="button" value="Submit" onclick="return f1()"/>
</body>

</html>

Tuesday 26 November 2013

Take Any String from User And Print How many Vowels are Present in that string

Like:-

a=1
e=1
i=1
o=1
u=1

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function vowelCount()
        {
            var str = f1.t1.value;
            var vowel = ['a', 'e', 'i', 'o', 'u'];

            for (var i = 0; i < vowel.length; i++)
            {
                count = 0;
                for (var j = 0; j < str.length; j++)
                {
                    if (vowel[i] == str[j])
                    {
                        count++;
                    }
                }
                if(count!=0)
                document.write(vowel[i] + '=' + count+"<br/>");
            }

        }
    </script>
</head>
<body>
<form id="f1">
<div id="div1">
<fieldset style="width:30%;margin:auto;margin-top:20%;background:orange" align="center">
<legend>Input Area</legend>
<textarea placeholder="Enter any message.." id="t1" rows="10"></textarea><br />
<input type="button" onclick="vowelCount()" value="submit"/>
</fieldset>
</div>
</form>
</body>
</html>

Take Multiple values from user using Promt properties in JS

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var num = document.getElementById("txtNum").value;
            var arr = new Array();
            var add=0;
            for (var i = 1; i <= num; i++) {
                var input = prompt("plz input value..");
                arr[i] = input;
                add = add + arr[i];
                alert(add);
            }
            alert("thank u..");
        }
        alert("HI");
       
    </script>
</head>
<body>
<input id="txtNum" type="text" placeholder="Enter no only.." />
<input id="btnNum" type="button" value="button" onclick="f1()" />
</body>


</html>

Monday 25 November 2013

Take a string input from user Replace the part of a string with desired character.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script type="text/javascript">

        function f1() {
            var str = document.getElementById("txtVal").value;
            var desiredchar = '@';
            var temp;
            var arr = new Array();
            for (var i = 0; i <= str.length - 1; i++) {
               
                arr[i] = str.charAt(i);
                }
                for (j = 0; j <= str.length - 1; j++) {


                    if (arr[j] == 'a') {

                        temp = arr[j];
                        arr[j] = desiredchar;
                        desiredchar = temp;
                    }
                    arr[j];
                }
                for (k = 0; k <= str.length - 1; k++) {
                  document.write(arr[k]);
                }
        }
   
    </script>
</head>
<body>
<input type="text" id="txtVal" />
<input type="button" value="Submit" onclick="f1()" />

</body>
</html>

Write your own regular expression in JS for valid e-mail ID, username accepting alphabets and digits, and land line number.For land-line number your input should be in format of : countrycode-statecode-number Ex.(+91-40-40151017) here +91 is country code 40 is state code eight digit land line number .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var name = document.getElementById("txtName").value;
            var regxname = /[a-z]{1}\d*/;
            var checkname = regxname.test(name);
         
            var email = document.getElementById("txtEmailId").value;
            var regxemail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
            var checkemail = regxemail.test(email);

            var phone = document.getElementById("txtLandLineNo").value;
            var regxphone = /\d{2}([-]*)\d{2}([-]*)\d{8}/;
            var checkphone = regxphone.test(phone);
         
            if (name == null || name == "") {
                alert("Please Enter Name");
                return false;
            }
            if (checkname == null || checkname == "") {

                alert("Name Enter Start with letters..");
                return false;
            }
//            else {

//                alert("Name Successfully Entered..");
//                return true;
//            }

            if (email == null || email == "") {
                alert("Please Enter Email");
                return false;
            }
            if (checkemail == null || checkemail == "") {

                alert("Email Enter with Proper Format..");
                return false;
            }
//            else {

//                alert("Email Successfully Entered..");
//                return true;
//            }

             if (phone == null || phone == "") {
                 alert("Please Enter Land phone No..");
                 return false;
            }
            if (checkphone == null || checkphone == "") {

                alert("Phone Enter with Proper Format..");
                return false;
            }
            else {

                alert("Phone Successfully Entered..");
                return true;
            }
           

        }
   
   
    </script>

</head>
<body>
<form action="HTMLPage2.htm" >
<div align="center" style="background-color: Silver" >
<table>
<tr>
<td colspan='3'>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Registration Form
</td>
</tr>

<tr>
<td>Name</td>
<td>:</td>
<td>
<input id="txtName" type="text"  />
</td>
</tr>
<tr>
<td>E-mail Id</td>
<td>:</td>
<td>
<input id="txtEmailId" type="text"  />
</td>
</tr>
<tr>
<td>Land-Line Number</td>
<td>:</td>
<td>
<input id="txtLandLineNo" type="text"  />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
   
<input id="btnSubmit" type="button" value="Submit" onclick="return f1()" />
</td>
</tr>

</table>
</div>

</form>

</body>
</html>

Friday 22 November 2013

Logical Pattern Question And Answer in JS

Like:-

    a
   ei
  oua
 eiou
aeiou

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
   
    <script type="text/javascript">
    function f1(){
        var arr = ['a','e','i','o','u'];
        var inc=0;
        var num=document.getElementById("txtNum").value;
        for (var row = 1; row <= num; row++) {
            for (var space = num-row; space >= 1; space--) {
                document.write("&nbsp;");
            }
            for (var column = 1; column <= row; column++) {
                document.write(arr[inc]);
               
                inc++;
                if (inc == 5) {
                    inc = 0;
                }

            }
            document.write("<br/>")
       
        }
        }
        alert("hi");
    </script>
</head>
<body>
<input type="text" id="txtNum" />
<br />
<input type="button" value="Button" onclick="f1()" />

</body>
</html>

Logical Pattern Questions And Answers in JS

Like:-

        1
      21
    321
  4321
54321

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var num = document.getElementById("txtNum").value;
            for (var i = 1; i <= num; i++) {
                for (var sp = num-i; sp >= 1; sp--) {
                    document.write("&nbsp;");
                }
                for (var j = i; j >= 1; j--) {
                    document.write(j);
                }
                document.writeln("<br/>");
            }

        }
   
    </script>
</head>
<body>
<input id="txtNum" type="text" />
    <input id="btnPattern" type="button" value="button" onclick="f1()"/>

</body>
</html>

Logical Pattern Questions And Answers using JS

Like:-

1
12
123
1234
12345

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1() {
            var num = document.getElementById("txtNum").value;
            for (var i = 1; i <= num; i++) {
              
                for (var j =1; j <= i; j++) {
                    document.write(j);
                }
                document.writeln("<br/>");
            }

        }
  
    </script>

</head>
<body>
<input id="txtNum" type="text" />
    <input id="btnPattern" type="button" value="button" onclick="f1()"/>

</body>
</html>

Logical Pattern Questions And Answers in JS

Like:-

 54321
   4321
     321
       21
         1

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

     <script type="text/javascript">
         function f1() {
             var num = document.getElementById("txtNum").value;
             for (var i = 1; i <= num; i++) {
                 for (var sp =1 ; sp <= i; sp++) {
                     document.write("&nbsp;");
                 }
                 for (var j = num - i + 1; j >= 1; j--) {
                     document.write(j);
                 }
                 document.writeln("<br/>");
             }

         }
  
    </script>
</head>
<body>
<input id="txtNum" type="text" />
    <input id="btnPattern" type="button" value="button" onclick="f1()"/>

</body>
</html>

Logical Pattern Questions And Answers using JS

Like:-
12345
1234
123
12
1

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
    function f1(){
    var num=document.getElementById("txtNum").value;
    for (var i = 1; i <= num; i++) {
        for (var j = 1; j <= num-i+1; j++) {
            document.write(j);
        }
        document.writeln("<br/>");
    }
  
    }
  
    </script>
</head>
<body>
    <input id="txtNum" type="text" />
    <input id="btnPattern" type="button" value="button" onclick="f1()"/>
</body>
</html>

Thursday 21 November 2013

Design the page as:-

Like

Dynamically add element in form
Select the element and hit Add to add it in form.
 

Result:-

Select the element and hit Add to add it in form.
 

Ans:-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1(type) {
            var cmbBox = document.createElement("input");
            cmbBox.setAttribute("value", type);
            cmbBox.setAttribute("type", type);
            cmbBox.setAttribute("name", type);
            var n = document.getElementById("p1");
            n.appendChild(cmbBox);
        }
       
    </script>
</head>
<body>
<form action="HTMLPage.htm" id="form1">
<b>Dynamically add element in form</b>
<br />
Select the element and hit Add to add it in form.
<div>
<select name="combo" id="comb1">
<option value="textbox">TextBox</option>
<option value="Button">Button</option>
<option value="CheckBox">CheckBox</option>
<option value="Radio">RadioButton</option>
<option value="ComboBox">ComboBox</option>
</select>
<input type="button" value="Submit" onclick="f1(document.forms[0].comb1.value)" />
</div>
<div>
<p id="p1"></p>
</div>
</form>
</body>
</html>

Design Html Page as using java script In that If you add any subject it should go in tp Combobox List.

Like:-

Add TO ComboBox:  

Combo Box: 

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function f1(a,b) {
            var txtBox = document.getElementById("txtSubject");
            var cmbBox = document.getElementById("txtCombo");
            var option = document.createElement("option");
            option.text = txtBox.value;
            option.value = txtBox.value;

            if (txtCombo.add(option, null))
             {

                 alert("hi")
            }
         }
    </script>
</head>
<body>
<div>
Add TO ComboBox:
<input type="text" id="txtSubject" value="Enter Any Subject" />
<input type="button" value="Submit" onclick="f1()"/>
</div>
<br />
<div>
Combo Box:
<select name="combo" id="txtCombo">
</select>
</div>
</body>
</html>

Tuesday 19 November 2013

Logical Pattern Question using JavaScript:

Like

s=2
u=1
b=1
a=1
s=2

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>
        function CallMe() {
            var num = document.getElementById("txtString").value;
            var count = 0;
            for (var i = 0; i <= num.length - 1; i++) {

                count = 0;
                for (var j = 0; j <= num.length - 1; j++) {
                    if (num[i] == num[j]) {
                        count++;
                    }

                }

                document.write(num[i] + "=" + count + "<br/>");
            }
        }
                alert("hi")

    </script>
</head>
<body>
    <input id="txtString" type="text" placeholder="Enter Any String.."/>
    <input id="btnSubmit" type="button" value="button" onclick="CallMe()" />
</body>
</html>

Logical Pattern Question using JavaScript:

Like
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>
        function CallMe() {
            var num = document.getElementById("txtNum").value;

            for (var i = 1; i <= num; i++)
             {
                 for (var j = 1; j <= i; j++)
                {

                   document.write(i+" ");

                }
                document.write("<br/> ");
                }
           
            }
                alert("hi")

    </script>
</head>
<body>
    <input id="txtNum" type="text" />
    <input id="btnSubmit" type="button" value="button" onclick="CallMe()" />
</body>
</html>

Logical Pattern Question using JavaScript:

Like
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>
        function CallMe() {
            var num = document.getElementById("txtNum").value;

            for (var i = 1; i <= num; i++)
             {
                 for (var j = 1; j <= i; j++)
                {

                   document.write(j+" ");

                }
                document.write("<br/> ");
                }
           
            }
                alert("hi")

    </script>
</head>
<body>
    <input id="txtNum" type="text" />
    <input id="btnSubmit" type="button" value="button" onclick="CallMe()" />
</body>
</html>

Create an HTML page to take a number as input from user and display the Multiplication table of the Number in grid as below format using JavaScript:

If User inputs 2 then output will be:-

2x1
=
2
2x2
=
4
2x3
=
6
2x4
=
8
2x5
=
10
2x6
=
12
2x7
=
14
2x8
=
16
2x9
=
18
2x10
=
20

Ans:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script>

        function sai() {

            var no = document.getElementById("txtno").value;
         
            for (var i = 1; i < 11; i++) {
            var res = no * i;
                document.write("<table border=1><tr><td>"+no+"</td><td>"+"*"+"</td><td>"+i+"</td><td>" + "=" + "</td><td>"+res+"</td></tr></table>");

            }
          alert(no)
        }
    
   </script>
  
</head>
<body>
<table>
<tr>
<td>
    <input id="txtno" type="text" />
</td>
<td>
    <input id="Submit1" type="submit" onclick="sai()" value="submit" />

</td>
</tr>
</table>
</body>
</html>

Pattern Logical Questions in JavaScript Like:

12345
12345
12345
12345
12345

Ans:

<html>
<head>
<script type="text/javascript">
function f1(){
var num=document.getElementById("txtNum").value;
for(var i=1;i<=5;i++)
{
for(var j=1;j<=5;j++)
{
document.write(j);
}
document.write("<br/>")
}
}

</script>
</head>
<body>
<input type="text" id="txtNum"/>
<br/>
<input type="button" value="Submit" onclick="f1()"/>
</body>
</html>