javascript sorting program in html

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aish123
    New Member
    • Jul 2015
    • 11

    #16
    are u telling that more than one number in an input box is invalid??

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #17
      no, I tell you that your program logic is busted.

      Comment

      • aish123
        New Member
        • Jul 2015
        • 11

        #18
        Code:
        <html>
        <head>
        <title>
        This is the real sorting.....
        </title>
        </head>
        <script type="text/javascript">
        var numbers= new array(6);
        function swap(i,j)
        {
        
        }
        function selectionSort()
        {
            var largest;
            for (i=0; i<5; i++)
            {
                largest=0;
                for (j=1; j< (6 - i); j++)
                {
                        if (numbers[largest] < numbers[j] )
                        {
                                largest=j;
                                
                        }
                }
                swap( largest, (5-i) );
                
             }
        }
        
        
        
        </script>
        <body bgcolor=pink>
        <form name="form1">
        <h1>Input Section</h1>
        <table>
        <tr>
        <th>0</th>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>4</th>
        <th>5</th>
        
        </tr>
        <tr>
        <td>
        <input type="text" name="i0" size="4">
        </td>
        <td>
        <input type="text" name="i1" size="4">
        </td>
        <td>
        <input type="text" name="i2" size="4">
        </td>
        <td>
        <input type="text" name="i3" size="4">
        </td>
        <td>
        <input type="text" name="i4" size="4">
        </td>
        <td>
        <input type="text" name="i5" size="4">
        </td>
        
        </tr>
        </table>
        
        
        <input type=button value="Sort" name="selSort"
        onClick="sort()">
        <h1>Output Section</h1>
        Once you click on the sort button above, the numbers in boxes will be sorted
        accordingly and then be placed in these boxes.
        <table>
        <tr>
        <td>
        <input type="text" name="o0" size="4">
        </td>
        <td>
        <input type="text" name="o1" size="4">
        </td>
        <td>
        <input type="text" name="o2" size="4">
        </td>
        <td>
        <input type="text" name="o3" size="4">
        </td>
        <td>
        <input type="text" name="o4" size="4">
        </td>
        <td>
        <input type="text" name="o5" size="4">
        </td>
        
        </tr>
        </table>
        
        
        </form>
        
        </body>
        </html>
        pls tell any corrections...a nd how to complete the pgm
        Last edited by Dormilich; Jul 14 '15, 02:19 PM. Reason: please use code tags

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #19
          why do you insist on creating your own sort() implementation?

          Comment

          • aish123
            New Member
            • Jul 2015
            • 11

            #20
            i hav to do it without built in functions....th atsy........... .

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #21
              that would have been nice to know in the first place …

              anyways, the first thing to do is analysing the current problems.

              - #1 is the conversion from an input to an array
              - #2 is the sorting of the array

              what you need to do is solve each problem separately instead of trying all at once.

              there are different approaches you could do.

              - make a temporary page that only concerns with a single problem. i.e. you completely neglect problem #2 while working on #1 (and vice versa)

              - mock all other problems while working on one. i.e. use use Array.sort() while working on problem #1 and use a predefined array as input while working on problem #2.

              Comment

              Working...