将旧值从 javascript 传递回 javabean
我有这段 javascript:
<script type="text/javascript">
function show_confirm()
{
var type = '<%= nameBean.getTxnType() %>';
var old_cd = '<%= nameBean.getCode() %>';
var new_cd = document.getElementById("tbCode").value;
var cd;
if (type == "Update")
{
if(old_cd != new_cd)
{
var response = confirm("Code already exists. Do you want to replace it?");
if (response){
document.NameUpdate.submit();
}
else{
cd = old_cd;
}
}
</script>
这就是我在 jsp 页面中执行的操作来调用此脚本:
<INPUT TYPE=SUBMIT NAME="action" onclick="show_confirm()" VALUE="Save Changes">
当我点击“确定”时它工作正常..但我的问题是如何将 old_cd 的值传递回 bean,以便它不会使用用户在 tbcode 框中输入的新代码来更新它。当用户点击取消时,我想忽略在文本框中输入的值,而不是更新数据库中的该字段
I have this piece of javascript:
<script type="text/javascript">
function show_confirm()
{
var type = '<%= nameBean.getTxnType() %>';
var old_cd = '<%= nameBean.getCode() %>';
var new_cd = document.getElementById("tbCode").value;
var cd;
if (type == "Update")
{
if(old_cd != new_cd)
{
var response = confirm("Code already exists. Do you want to replace it?");
if (response){
document.NameUpdate.submit();
}
else{
cd = old_cd;
}
}
</script>
and this is what i am doing in my jsp page to invoke this script:
<INPUT TYPE=SUBMIT NAME="action" onclick="show_confirm()" VALUE="Save Changes">
Its working fine when I hit ok.. but my question is how can i pass the value of old_cd back to the bean so it wont update it with the new code that was entered by the user in the tbcode box.. when user hit cancel i want to ignore what value was entered in textbox and not to update that field in database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对这里的用例并不完全清楚,但这里有几个答案:
如果问题是“当用户点击取消时如何阻止表单提交?”,那么答案是 return
false:
如果无论用户点击哪一个都需要提交表单,那么您可能需要在隐藏的
input
字段中提交旧值,并有一个告诉服务器用户点击“取消”(可能是另一个隐藏字段)的方法,例如:和javascript:
I'm not entirely clear on the use case here, but here are a couple of answers:
If the question is, "how do I stop the form from submitting when the user hits cancel?", then the answer is, return
false
in the click handler:If you need to submit the form no matter which one the user clicks, then you probably need to submit the old value in a hidden
input
field and have a way to tell the server that user hit "cancel" (probably another hidden field), e.g.:and javascript: