- A Write A Javascript Code Fragment That Obtains Five Numbers From Text Fields Stores Them In An Array Uses The Sort 1 (170.52 KiB) Viewed 25 times
(a) Write a JavaScript code fragment that obtains five numbers from text fields, stores them in an array, uses the sort
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
(a) Write a JavaScript code fragment that obtains five numbers from text fields, stores them in an array, uses the sort
(a) Write a JavaScript code fragment that obtains five numbers from text fields, stores them in an array, uses the sort function to sort it into descending numerical order and displays the sorted array in a presentation tag on the HTML page from which the script was invoked. All interaction with the document object model should be done using JQuery. You should assume that the input fields have id attributes idi, id2, id3, id4 and id5 and the presentation tag has the id attribute sorted. (b) The following HTML form allows a user to supply details for purchase of tickets for a concert. (Some of the options from the select element have been omitted). When the submit button is clicked a JavaScript function called validate is invoked to check that the name fields contain data, the card number satisfies a CRC check and that the number of tickets is an integer in the range 1 to 10. <form action = "page2.jsp" method "post" name = "forml" onsubmit = "validate()" > <table> <tr> <td> Name </td> <td> <input id = "n" name = "name"> </td> </tr> <tr> <td> Card number </td> <td> <input id = "C" name = "card"> </td> </tr> <tr> <td> Performance </td> <td> <select id = "p" name = "perf"> <option value = "1" selected> 2.30pm Aug 17 </option> <option value = "2"> 7.30pm Aug 17 </option> </select> </td> </tr> <tr> <td> Number of tickets </td> <td> <input id = "t" name = "tickets"> </td> </tr> </table> <input type = "submit" value = </form> "Book tickets" /> (1) Write a JavaScript function called validate that will perform the validation described above; it should display an appropriate alert if any input is invalid. You may assume a function to do the CRC check has already been written. (ii) Explain why it is desirable to perform both client-side and server-side validation of form data such as in the example above.