从同一个JSP中的onclick()文本字段获取值参数

时间:2021-08-23 08:18:49

I'm writing on a Web Application (Crowdfunding Platform - Student Project) and my Problem is a JSP page where the user can back a Project. I have a form field for the User where he can type in the amount of his donation and after this the same JSP should display the associated rewards. Finally he can submit the action to the Servlet.

我正在写一个Web应用程序(Crowdfunding Platform - 学生项目),我的问题是一个JSP页面,用户可以在其中支持项目。我有一个用户的表单字段,他可以输入他的捐赠金额,然后相同的JSP应显示相关的奖励。最后,他可以将动作提交给Servlet。

<input type="text" class="login_spende" maxlength="10" id="spendeBetrag" name="spendeBetrag" value="1 &euro;" onFocus="if(this.value=='1 &euro;') this.value='';" onBlur="if(this.value=='')this.value='1 &euro;';">

<input type="button" value="Reward auswählen" onclick="doSomething()">

This is the code to get the associated rewards with reference to the donation

这是参考捐赠获得相关奖励的代码

<%
        List<RewardDAO> rewards = RewardDB.getProjektRewardsByBetrag(spendeBetrag, projektid);
            for (RewardDAO reward : rewards) {
        %>  
        <div class="rewards_spende_box">
            <div>

            </div>
            <div class="rewards_spende" style="background-color:#BBBBBB;" >
            <input type="checkbox" class="checkbox_spende" name="spendeReward" value="<%= reward.getRewardID() %>" />
            <div class="betrag_spende"><%=reward.getBetrag()%>&euro;</div>
            <div class="rewardtext_projektseite"><%=reward.getBeschreibung()%></div>
            </div>
        </div>  
        <%
            }
        %>  

The Word "spendeBetrag" is german for "donationValue" ;)

“spendeBetrag”这个词是“donationValue”的德语;)

But how is it possible to load the reward list after the user confirmed his donation value because the paramater "spendeBetrag" in getProjektRewardsByBetrag(spendeBetrag, projektid); depends on the text field above.

但是,在用户确认他的捐赠价值之后如何加载奖励清单是可能的,因为getProjektRewardsByBetrag中的参数“spendeBetrag”(spendeBetrag,projektid);取决于上面的文本字段。

My idea was it to do this with JavaScript, the reward list is on display: none but when the user pushed the button with the donation it should be display: block; but I'm unable to paste the value "spendeBetrag" into the Java code.

我的想法是用JavaScript执行此操作,奖励列表显示:无,但当用户按下捐赠按钮时,应显示:block;但是我无法将值“spendeBetrag”粘贴到Java代码中。

Another idea was it to paste this code in an extra Servlet but then I have to load the page twice and this is not what I want.

另一个想法是将这个代码粘贴到一个额外的Servlet中然后我必须加载页面两次,这不是我想要的。

I hope anyone has a better idea. Thanks for helping :)

我希望任何人都有更好的主意。谢谢你的帮助:)

1 个解决方案

#1


0  

Try using AJAX. There you can post data without reloading the whole Page.

尝试使用AJAX。在那里你可以发布数据而无需重新加载整个页面。

#1


0  

Try using AJAX. There you can post data without reloading the whole Page.

尝试使用AJAX。在那里你可以发布数据而无需重新加载整个页面。