I am trying to call the resetyear function and its getting called also but the flow stops at alert("over"), it doesnt tranfer its control to resetmaster. Please suggest me something.
我试图调用resetyear函数,它也被调用,但流程停止在警报(“结束”),它不会将其控制转移到resetmaster。请给我一些建议。
String flag = "";
flag = (String) session.getAttribute("flag");
System.out.println("flag = " + flag);
if (flag == null) {
flag = "";
}
if (flag.equals("yes")) {
%>
<script>
alert(1);
// resetyear();
dontreset();
//document.getElementById("checkyear").value = "1";
//alert(document.getElementById("checkyear").value);
</script>
<%} else if(flag.equals("no"))
{%>
<script>
alert(2);
//document.getElementById("checkyear").value = "2";
//alert(document.getElementById("checkyear").value);
resetyear();
</script>
<%}else{}%>
function resetyear(){
if(confirm("DO YOU WANT TO RESET THE YEAR?"))
{
alert("hello");
//document.forms['indexform'].action = "resetmaster";
//alert(document.forms['indexform'].action);
//document.forms['indexform'].submit();
alert("over");
form.action = "resetmaster";
form.submit();
alert(1);
}
5 个解决方案
#1
47
For me it works:
对我来说它有效:
document.getElementById("checkyear").value = "1";
alert(document.getElementById("checkyear").value);
http://jsfiddle.net/zKNqg/
Maybe your JS is not executed and you need to add a function() {} around it all.
也许你的JS没有被执行,你需要在它周围添加一个函数(){}。
#2
5
You need to run your script after the element exists. Move the <input type="hidden" name="checkyear" id="checkyear" value="">
to the beginning.
您需要在元素存在后运行脚本。将移到开头。
#3
5
It's seems to work fine in Google Chrome. Witch browser are you using? Here the proof http://jsfiddle.net/CN8XL/
它似乎在谷歌浏览器中运行良好。您正在使用Witch浏览器吗?这里的证明http://jsfiddle.net/CN8XL/
Any how you can also access to the input value parameter through the document.FormName.checkyear.value
. Of course you have to wrap in the input in a <form>
tag like with the proper name
attribute, like shown below:
您还可以通过document.FormName.checkyear.value访问输入值参数。当然,你必须在
<form name="FormName">
<input type="hidden" name="checkyear" id="checkyear" value="">
</form>
Have you considered to use the jQuery Library? Here the docs for .val()
function.
你考虑过使用jQuery库吗?这里是.val()函数的文档。
#4
1
The first thing I will try - determine if your code with alerts is actually rendered. I see some server "if" code in what you posted, so may be condition to render javascript is not satisfied. So, on the page you working on, right-click -> view source. Try to find the js code there. Please tell us if you found the code on the page.
我将尝试的第一件事 - 确定您的代码是否实际呈现了警报。我在你发布的内容中看到了一些服务器“if”代码,因此可能是渲染javascript不满意的条件。因此,在您正在处理的页面上,右键单击 - >查看源代码。尝试在那里找到js代码。如果您在页面上找到了代码,请告诉我们。
#5
1
Your code for setting value for hidden input is correct. Here is the example. Maybe you have some conditions in your if
statements that are not allowing your scripts to execute.
您为隐藏输入设置值的代码是正确的。这是一个例子。也许你的if语句中有一些条件不允许你的脚本执行。
#1
47
For me it works:
对我来说它有效:
document.getElementById("checkyear").value = "1";
alert(document.getElementById("checkyear").value);
http://jsfiddle.net/zKNqg/
Maybe your JS is not executed and you need to add a function() {} around it all.
也许你的JS没有被执行,你需要在它周围添加一个函数(){}。
#2
5
You need to run your script after the element exists. Move the <input type="hidden" name="checkyear" id="checkyear" value="">
to the beginning.
您需要在元素存在后运行脚本。将移到开头。
#3
5
It's seems to work fine in Google Chrome. Witch browser are you using? Here the proof http://jsfiddle.net/CN8XL/
它似乎在谷歌浏览器中运行良好。您正在使用Witch浏览器吗?这里的证明http://jsfiddle.net/CN8XL/
Any how you can also access to the input value parameter through the document.FormName.checkyear.value
. Of course you have to wrap in the input in a <form>
tag like with the proper name
attribute, like shown below:
您还可以通过document.FormName.checkyear.value访问输入值参数。当然,你必须在
<form name="FormName">
<input type="hidden" name="checkyear" id="checkyear" value="">
</form>
Have you considered to use the jQuery Library? Here the docs for .val()
function.
你考虑过使用jQuery库吗?这里是.val()函数的文档。
#4
1
The first thing I will try - determine if your code with alerts is actually rendered. I see some server "if" code in what you posted, so may be condition to render javascript is not satisfied. So, on the page you working on, right-click -> view source. Try to find the js code there. Please tell us if you found the code on the page.
我将尝试的第一件事 - 确定您的代码是否实际呈现了警报。我在你发布的内容中看到了一些服务器“if”代码,因此可能是渲染javascript不满意的条件。因此,在您正在处理的页面上,右键单击 - >查看源代码。尝试在那里找到js代码。如果您在页面上找到了代码,请告诉我们。
#5
1
Your code for setting value for hidden input is correct. Here is the example. Maybe you have some conditions in your if
statements that are not allowing your scripts to execute.
您为隐藏输入设置值的代码是正确的。这是一个例子。也许你的if语句中有一些条件不允许你的脚本执行。