Write a complete webpage with embedded JavaScript code Assum

Write a complete webpage with embedded JavaScript code. Assume this webpage has multiple

elements. The JavaScript code on this page should: 1) Read a positive integer k from the keyboard with prompt function. 2) Rotate all

elements k places downward circularly. 3) Give an error message if no

element exists on this page. Note: 1) The JavaScript getElementsByTagName() method should be used to create an array of

elements. You may need make a copy of this array. 2) A loop MUST be used to implement the rotation such that the code could handle any table on the page as long as it is the only table on this page. 3) You may need add a button to refresh the page and all above coed into the onclick() event handler function.

Solution

1) The code to read a positive integer k from the keyboard with prompt function is as follows. (Note : I have put a checker that check sif the number if it is positive and if it is not it asks for the user input again)

<script type=\"text/javascript\">
<!--
function getValue(){
var k = prompt(\"\ Enter a positive integer : \");
document.write(\"\ You have entered : \" + k);
             
       var check;

       function isNormalInteger(str) {
        var n = ~~Number(str);
       return String(n) === str && n >= 0;
           }

       check=isNormalInteger(k);
      
       if(!check)
       {document.write(\"\ You have not entered a correct value please enter again\");
       getValue();}
          
       }

//-->
</script>

//To call the function using a onclick box the code would be

<form>
<input type=\"button\" value=\"Click Here\" onclick=\"getValue();\" />
</form>

2. To use the javascript getElementsByTagName() and copy of that array method and to rotate all elements k places the code would be as follows:-

<script type=\"text/javascript\">
<!--

       var listcpy;

       function getList() {
  
       var list = document.getElementsByTagName(\'LI\');
       for(var i=0; i<list.length; i++) {
           document.getElementById(\'LI\').innerHTML = list[i].innerHTML;
               listcpy[i]=list[i];
           }  
      
       }
      
       getList();


       function rotate( array , times ){
        array = array.slice();
       while( times-- ){
       var temp = array.shift();
       array.push( temp )
       }
       return array;
       }

//-->
</script>

3. The code for adding an onclick box to refresh the page would be as follows :-

<form>
    <input type=\"button\" value=\"Refresh Page\" onClick=\"refresh\">
</form>

4. The code to check if No elements exists on the page would be :-

Write a complete webpage with embedded JavaScript code. Assume this webpage has multiple elements. The JavaScript code on this page should: 1) Read a positive i
Write a complete webpage with embedded JavaScript code. Assume this webpage has multiple elements. The JavaScript code on this page should: 1) Read a positive i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site