<button id="addCustomerInput">Add input</button><div id="inputContainer"></div> On click of this button an input tag is added with a common class of "customerInput".When the user puts in any value in these input tags the unique values are to be saved in the database table named "users_customer_inputs" by replacing the existing ones. The javaScript code to send the data of all the inputs is stated below. Will the following achieve the aforesaid objective or is there any issue with the code if so identify the issue and resolution? $("#addCustomerInput").click(()=>{ $("#inputContainer").append("<input class="customerInput" type='text' placeholder='Input values'/>"); $(".customerInput").on('change', function() { var customerInputs = [] $(".customerInput").each(function(){ customerInputs.push($(this).val())}); $.ajax({ url: '/users/computationModule/', data: { 'customerInputs': JSON.stringify(customerInputs), 'operation': 'saveCustomerInputs', }, type: "POST", dataType: "json", success: ()=>{ alert("Inputs successfully saved"); }, error: function () { alert("Error"); } }); });}); Option 1: The javaScript code stated does not have any issues and will achive the mentioned objective.Option 2: The javaScript code stated will not work as there is an issue with the syntax of the code.Resolution : Change the html string inside append method to "<input class='customerInput' type='text' placeholder='Input values'/>"Option 3: The javaScript code stated will not work as it will result in same event being set on the input tags multiple times resulting in multiple triggers of the AJAX query and consequently multiple alerts on screen. Resolution : Turn off all the existing "change" events on the customer Input class using off('change') before registering new event.Option 4: Both 2 and 3(1 Point)Option 1Option 2Option 3Option 4
Question
<button id="addCustomerInput">Add input</button><div id="inputContainer"></div> On click of this button an input tag is added with a common class of "customerInput".When the user puts in any value in these input tags the unique values are to be saved in the database table named "users_customer_inputs" by replacing the existing ones. The javaScript code to send the data of all the inputs is stated below. Will the following achieve the aforesaid objective or is there any issue with the code if so identify the issue and resolution? ("#addCustomerInput").click(()=>{ ("#inputContainer").append("<input class="customerInput" type='text' placeholder='Input values'/>"); (".customerInput").on('change', function() { var customerInputs = [] (".customerInput").each(function(){ customerInputs.push((this).val())}); .ajax({ url: '/users/computationModule/', data: { 'customerInputs': JSON.stringify(customerInputs), 'operation': 'saveCustomerInputs', }, type: "POST", dataType: "json", success: ()=>{ alert("Inputs successfully saved"); }, error: function () { alert("Error"); } }); });}); Option 1: The javaScript code stated does not have any issues and will achive the mentioned objective.Option 2: The javaScript code stated will not work as there is an issue with the syntax of the code.Resolution : Change the html string inside append method to "<input class='customerInput' type='text' placeholder='Input values'/>"Option 3: The javaScript code stated will not work as it will result in same event being set on the input tags multiple times resulting in multiple triggers of the AJAX query and consequently multiple alerts on screen. Resolution : Turn off all the existing "change" events on the customer Input class using off('change') before registering new event.Option 4: Both 2 and 3(1 Point)Option 1Option 2Option 3Option 4
Solution
The JavaScript code stated will not work as it will result in the same event being set on the input tags multiple times, resulting in multiple triggers of the AJAX query and consequently multiple alerts on the screen. The resolution is to turn off all the existing "change" events on the customerInput class using off('change') before registering a new event. Therefore, the correct option is Option 3.
Similar Questions
Which property is used to get the value of an input field in JavaScript?textinnerHTMLvalueinput
Technique to save html data in the database Automatic synchronization of data between model and controller components Technique to bind database data to html control Automatic synchronization of data between model and view components
Which of the following can't be done with client-side JavaScript?Question 6Select one:a.Storing the form's contents to a database file on the serverb.None of the abovec.Sending a form's contents by emaild. Validating a form
1-7 HTML Forms: Input Types, Buttons And Text Field, Select, Option
Question No. 12Marks : 1.00 Technique to save html data in the database Automatic synchronization of data between model and controller components Technique to bind database data to html control Automatic synchronization of data between model and view components
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.