Java脚本验证表单时出现问题 [英] Java script Problem in the validation of the form

查看:63
本文介绍了Java脚本验证表单时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下所示:

My Code is shown below:

<script language="javascript" type="text/javascript">
 function validateFrm(){
var frm=document.forms["frm"]

if(trim(frm.txtEmailId.value)==""){
alert('Enter Email')
frm.txtEmailId.focus()
return false}

else if(trim(frm.txtPassword.value)==""){
alert('Enter Password')
frm.txtPassword.focus()
return false}


else if(trim(frm.ddlCreatePro.value)=="0"){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}


else if(trim(frm.txtFirstName.value)==""){
alert('Enter First Name')
frm.txtFirstName.focus()
return false}

else if ( ( frm.rbtMale.checked == false ) && ( frm.rbtnFemale.checked == false ) )
 {
 alert ( " choose your Gender" )
 return false}

else if(trim(frm.ddlDD.value)=="0"){
alert('Select Date')
frm.ddlDD.focus()
return false}

else if(trim(frm.ddlMM.value)=="0"){
alert('Select Month')
frm.ctl00_ddlMM.focus()
return false}

else if(trim(frm.ddlYYYY.value)=="0"){
alert('Select Year')
frm.ddlYYYY.focus()
return false}

else if(trim(frm.ddlState.value)=="0"){
alert('Select State')
frm.ddlState.focus()
return false}

else if(trim(frm.ddlCity.value)=="0"){
alert('Select City')
frm.ctl00_cphBody_ddlCity.focus()
return false}

else if(trim(frm.txtMobileNo.value)==""){
alert('Enter Mobile')
frm.txtMobileNo.focus()
return false}

else if(trim(frm.ddlMaritalStatus.value)=="0"){
alert('Select Material Status')
frm.ddlMaritalStatus.focus()
return false}

else if(trim(frm.ddlReligion.value)=="0"){
alert('Select Religion')
frm.ddlReligion.focus()
return false}

else if(trim(frm.ddlCaste.value)=="0"){
alert('Select Caste')
frm.ddlCaste.focus()
return false}
 }
    </script>



我在save btn onclientclick中称呼它为



i am calling this in save btn onclientclick :

<asp:ImageButton ID="imgSave" runat="server" CssClass="btn1" AlternateText="Save"
                                    OnClick="imgSave_Click" OnClientClick="return validateFrm()" Style="height: 16px" />





这里的问题是验证工作到两个领域.从下拉的单词上的ddlCreatePro字段不起作用.

请让我知道我在上面的代码中有什么错误...





Problem here is the validation is working till two fields. it is not working from ddlCreatePro field on words which is drop down.

Please let me know what is my mistake in the above code...

推荐答案

使用它
else if(frm.ddlCreatePro.selectedIndex==0){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}


我现在看不到错误,但是请注意,您没有显示完整的页面内容.如果可以的话.真的,使用JavaScript.

我的第一个猜测是:在验证期间,在验证某些第一个字段之后会引发异常.可能存在其他问题,例如字段名称不匹配(同样,我看不到完整的页面).通常,如果您不在调试器下运行它和/或未启用JavaScript调试器(这是一个常见问题),您可能没有注意到这一点.通常,在生产模式下工作的HTTP服务器不会显示未处理的JavaScript异常.因此,您还可以捕获此方法周围的所有异常,并显示详细的异常信息.这样,您可以立即找到并解决问题.

—SA
I cannot see a bug right now, but note that you did not show the complete page content. If can be a problem. Really, use JavaScript.

My first guess is this: during validation, an exception is thrown after the validation of some first fields. There can be different problems, such as field name mismatch (again, I cannot see you complete page). Usually, if you run it not under debugger and/or the JavaScript debugger is not enabled (which is a usual problem), you might not have noticed that. Usually, HTTP servers working in production modes do not reveal unhandled JavaScript exceptions. So, you can also catch all exceptions around this method and show detailed exception information. This way, you can find and fix the problem in no time.

—SA


您好,您可以使用上面的代码或下面的代码:

Hi, You can use above code or use below code:

else if(frm.ddlCreatePro.options[frm.ddlCreatePro.selectedIndex].value=="0"){
alert('Select Create Profile For')
frm.ddlCreatePro.focus()
return false}


这篇关于Java脚本验证表单时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆