简体   繁体   English

提交后让表单字段保持可见

[英]Have a form field stay visible after a submit

I'll try to be clear. 我会努力弄清楚。 I have a listbox with 3 entries in it, and when my entry number 2 is selected it makes a field, which is by default hidden, become visible. 我有一个包含3个条目的列表框,当选择我的条目号2时,它会使一个字段(默认情况下是隐藏的)变得可见。

Then after the form is submitted, the selected item stays in the listbox (already worked that out), but the field that became visible goes back to its default setting, hidden. 然后,在提交表单后,选定的项目将保留在列表框中(已经解决了),但是变为可见的字段返回到其默认设置(隐藏)。 I'd like it to stay visible, in case the submit didn't pass the validation requirements or whatever other reason. 我希望它保持可见状态,以防提交未通过验证要求或其他任何原因。

I know it has to be quite easy but I'm still getting used to HTML/PHP/Javascript. 我知道它必须非常容易,但是我仍然习惯于HTML / PHP / Javascript。

If you guys need any code parts I'll be more than happy to offer them. 如果你们需要任何代码部分,我将非常乐意提供它们。 I just don't want to post my full code for no reason, which is pretty messy and quite long. 我只是不想无故发布我的完整代码,这很乱而且很长。

Thanks in advance! 提前致谢!

EDIT: 编辑:

actually i just found it. 实际上我才发现它。 thanks for the help, putted me on the right track 感谢您的帮助,使我走上了正确的路

so heres the code, you just have to put this anywhere in the body tag. 因此,这里是代码,您只需将其放在body标签中的任何位置即可。

this will do any action onload. 这将在加载时执行任何操作。 so as my code goes it will check if the id of my list box is the number 2, if it is its gonna do the actons in the IF statement. 因此,随着我的代码的进行,它将检查我的列表框的ID是否为2,如果是,它将在IF语句中执行acton。 looks for my fields and put them visible. 寻找我的领域并将其显示。

<script>   
window.onload = function() {     
if (document.getElementById("topic2").value=="2")
{
document.getElementById("Agence").style.visibility='Visible';
document.getElementById("agence_tittle").style.visibility='Visible';
}

} 
</script>

您的表单提交功能是刷新页面还是将隐藏的字段/类设置回隐藏?

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

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