简体   繁体   English

如何在同一页面上显示用户输入以及删除选项

[英]how do i display user input on the same page, with the option to delete

Good day programmers. 程序员好日子。 I am very new to jsp/javascript but this site has helped me a lot so far, but i can use some more help or guidance for a problem i am having. 我对jsp / javascript非常陌生,但到目前为止,该站点对我有很大帮助,但是对于遇到的问题,我可以使用更多帮助或指导。 I am making a web app for creating and saving recipes. 我正在制作一个用于创建和保存配方的Web应用程序。 For my "add recipe" process, i have the user enter a recipe name, they are then directed to another page where they can choose an ingredient from a dropdown (populated from a sql db), enter a quantity, and then click a button to ad another ingredient. 对于我的“添加配方”过程,我让用户输入一个配方名称,然后他们被定向到另一个页面,他们可以从下拉列表中选择一种成分(从sql db中填充),输入数量,然后单击一个按钮。广告另一种成分。 What i wish to do is have the ingredient selected and the amount displayed to the user on the same page where they are choosing the ingredients. 我想要做的是选择成分,并在他们选择成分的同一页面上向用户显示数量。 I also want to add a button at the end of the "print out" that allows the user to remove that ingredient. 我还想在“打印输出”的末尾添加一个按钮,以允许用户删除该成分。
So far i am thinking that i should use a table and have a row created when the user adds an ingredient, then use the deleterow() method to remove that ingredient if desired. 到目前为止,我认为我应该使用一个表并在用户添加成分时创建一个行,然后根据需要使用deleterow()方法删除该成分。 Does anyone think this can work? 有人认为这可以工作吗? or have a better solution. 或有更好的解决方案。 PS: i am very new to jsp and javascript. PS:我对jsp和javascript非常陌生。 thanks in advance for any assistance rendered. 在此先感谢您提供的任何帮助。

You can use ajax to achieve this. 您可以使用ajax实现此目的。 For that using jQuery will make you writing a lot less number of lines of code. 为此,使用jQuery将使您编写的代码行更少。 So it will work like this, they have entered the recipe name. 这样就可以这样工作了,他们已经输入了配方名称。 Now using onblur on that field input, you load the dropdown of ingredients and give them option of entering quantity and selecting the ingredient with a button to save that data. 现在,在该字段输入上使用onblur ,您可以加载配料的下拉列表,并为他们提供输入数量和使用按钮选择配料的选项,以保存数据。 When they click on the button to save, after it getting saving into the database, you make an ajax call to load the recent added item with a button to delete it and when they click on delete, you make another ajax call to the database to delete it. 当他们单击要保存的按钮时,将其保存到数据库中后,您将进行ajax调用以加载最近添加的项目,并带有一个将其删除的按钮;当他们单击delete时,您将对数据库进行另一个ajax调用以删除它。 Here is a guide to ajax on javaScript https://developer.mozilla.org/en-US/docs/AJAX 这是javaScript上的Ajax指南https://developer.mozilla.org/en-US/docs/AJAX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM