简单的代码不起作用,如果为true,则javascript不会提交表单. [英] Simple code does not work javascript doest submit form if true....
本文介绍了简单的代码不起作用,如果为true,则javascript不会提交表单.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<form action="viewrecords.asp" method="post"> Date<input type="text" readonly="readonly" name="theDate" id="Date"/> <input type="button" value="Date" onclick="displayCalendar(document.forms[0].theDate,''yyyy/mm/dd'',this)"/>
如果返回true,则Java脚本不会提交表单
function chkvalid() { if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value==0) { alert("he"); return false; } else { return true; } } <input value="Show" onclick="return chkvalid();" type="button" />
解决方案
您是否已跟踪代码?看着源头?是什么让您认为元素具有您使用的名称?如果是因为您在ASP.NET中给了它们这些名称,则客户端ID在ClientID属性中.
但是,按照您的意思,我认为主要问题是出于我不了解的原因,您希望有一个按钮可以提交您的表格.您为什么希望此按钮提交表单?请编辑您的帖子以添加此信息.
< > < 头部 > < 脚本 =" 文本/javascript" < /script > < /head > < 正文 > < 表单 =" 方法 发布" < 输入 =" 提交" onclick 返回chkvalid( )" 值 显示" / > < 输入 =" 文本" =" 日期" / > < 输入 =" 文本" =" ddlModel" / > < /form > < /body > < /html >
简单选项的结合;
- 将类型从按钮更改为提交
- ,或将
document.myform.submit();
放在return true;
之前(将myForm更改为表单名称)
-编辑-
执行选项1.将按钮的类型从button更改为Submit并起作用.
< html > ; < 头部 > < 标题 > 标题< /title > < 脚本 =" 文本/javascript" < /script > < /head > < 正文 > < 表单 =" 方法 发布" < 输入 类型 =" id ">日期" / > < BR > < 输入 =" 文本" id ddlModel' / > < BR > < 输入 =" 显示" onclick 返回chkvalid( );" 类型 提交" / > < /form > < /body > < /html >
hi CG how you r doing? am editing a old site built in asp. it is just a html page... so and form is like this
<form action="viewrecords.asp" method="post"> Date<input type="text" readonly="readonly" name="theDate" id="Date"/> <input type="button" value="Date" onclick="displayCalendar(document.forms[0].theDate,''yyyy/mm/dd'',this)"/>
java script if return true does not submits the form
function chkvalid() { if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value==0) { alert("he"); return false; } else { return true; } } <input value="Show" onclick="return chkvalid();" type="button" />
解决方案
Have you traced the code ? looked at the source ? What makes you think that your elements have the names you used ? If it''s because you gave them those names in ASP.NET, then the client side id is in the ClientID property.
However, from what you''re saying, I think the main issue is that you expect a button to submit your form, for reasons that I don''t understand. Why do you expect this button to submit the form ? Pls edit your post to add this info.
<html> <head> <script type="text/javascript"> function chkvalid() { if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value=="0") { alert("He"); return false; } else { return true; } } </script> </head> <body> <form action="viewrecords.asp" method="post"> <input type="submit" onclick="return chkvalid()" value="Show" /> <input type="text" id="Date" /> <input type="text" id="ddlModel" /> </form> </body> </html>
This should do the trick.
Couple of simple options;
- Change the type from button to submit
- or place
document.myform.submit();
beforereturn true;
(change myForm to the name of the form)
-- EDIT --
Do option 1. change the type of the button from button to submit and it works.
<html> <head> <title>Title</title> <script type="text/javascript"> function chkvalid() { if(document.getElementById("Date").value=="" && document.getElementById("ddlModel").value=="0") { alert("he"); return false; } else { return true; } } </script> </head> <body> <form action="viewrecords.asp" method="post"> Date<input type="text" id='Date'/><BR> <input type="text" id='ddlModel'/><BR> <input value="Show" onclick="return chkvalid();" type="submit" /> </form> </body> </html>
这篇关于简单的代码不起作用,如果为true,则javascript不会提交表单.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文