[英]how can i get a value from inside a function using java script?
here is the function from inside a script 这是脚本内部的功能
function dosubmit()
{
if (getObj("Frm_Username").value == "")
{
getObj("errmsg").innerHTML = "Username cannot be empty.";
getObj("myLayer").style.visibility = "visible" ;
return;
}
else
{
getObj("LoginId").disabled = true;
getObj("Frm_Logintoken").value = "3";
document.fLogin.submit();
}
}
i want to get the value of getObj("Frm_Logintoken")
as i can't pull the value from #Frm_Logintoken
我想得到
getObj("Frm_Logintoken")
的值,因为我无法从#Frm_Logintoken
提取值
using document.getElementById("#Frm_Logintoken")
this gives me null 使用
document.getElementById("#Frm_Logintoken")
这给了我null
because Frm_Logintoken only gets it's value when i click submit . 因为当我点击提交时,Frm_Logintoken只获取它的值。
<input type="hidden" name="Frm_Logintoken" id="Frm_Logintoken" value="">
i found this online /getObj\\("Frm_Logintoken"\\).value = "(.*)";/g
but when i run it ... it gives me the same line again ! 我发现这个在线/
/getObj\\("Frm_Logintoken"\\).value = "(.*)";/g
但是当我运行它时...它再次给了我同样的线! it's full code https://hastebin.com/gurosatuna.xml 它的完整代码是https://hastebin.com/gurosatuna.xml
First: 第一:
Your checking if a value is empty with JS. 您使用JS检查值是否为空。 However this is NOT needed as HTML does this for you.
但是,这不是必需的,因为HTML会为您执行此操作。 Add a attribute required and the form will not submit as long this value is empty
添加所需的属性,只要此值为空,表单就不会提交
Documentation: https://www.w3schools.com/tags/att_input_required.asp
文档: https : //www.w3schools.com/tags/att_input_required.asp
Second: 第二:
You could use the event handler 'on submit'. 您可以在提交时使用事件处理程序。 The code is not complete enough to know if u did this but I suppose you just added a Click handler on the button.
代码不够完整,不知道你是否这样做,但我想你刚刚在按钮上添加了一个Click处理程序。
Documentation: https://www.w3schools.com/jsref/event_onsubmit.asp
文档: https : //www.w3schools.com/jsref/event_onsubmit.asp
When combining these two, you always have a username filled in and the code only executes when submitted. 组合这两个时,您总是填写用户名,代码仅在提交时执行。 I hope this helps, if not please leave a comment and I will edit this answer.
我希望这有帮助,如果没有请发表评论,我将编辑这个答案。
EDIT: the answer on this SO will also help (not the checked on but the one below) 编辑:这个SO的答案也会有所帮助(不是检查,而是下面的那个)
How can I listen to the form submit event in javascript? 如何在javascript中收听表单提交事件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.