are u telling that more than one number in an input box is invalid??
javascript sorting program in html
Collapse
X
-
pls tell any corrections...a nd how to complete the pgmCode:<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>Comment
-
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
Comment