如何在不同的不同选项卡中验证单个文本框 [英] How can I validate a single textbox in different different tabs

查看:58
本文介绍了如何在不同的不同选项卡中验证单个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单中我使用文本框作为Mobile no,我想在不同的选项卡中验证该文本框,因为我在所有选项卡中调用相同的表单:

选项卡是:

1.Prepaid tab

2.Postpaid tab

3.Dth tab

4.data card tab



现在当用户导航到第一个选项卡,第二个选项卡或第四个选项卡时,移动设备没有文本框只能接受10个数字但是当第四个选项卡被调用时它应该接受任何no数字



我尝试过:



函数IsNumeric(e) {

var specialKeys = new Array();

specialKeys.push(8); // Backspace

var keyCode = e.which? e.which:e.keyCode

var ret =((keyCode> = 48&& keyCode< = 57)|| specialKeys.indexOf(keyCode)!= -1);

document.getElementById(error)。style.display = ret? none:inline;

返回ret;

}

函数ValidateRecharge(rdvalue){

调试器;

var MobileNo = document.getElementById(txtMobileNo)。value;

var amt = document.getElementById(txtAmount)。value;

var errorMsg ='';

if(errorMsg ==''){

if(MobileNo ==){

errorMsg + =请输入手机号码|

}

// else {

// if(MobileNo.length < 10 || MobileNo.length> 10){

// errorMsg + =手机号码无效,请输入10位数手机号码|;

//}

//}

if(amt ==){

errorMsg + =请输入金额。 ;

}

}



if(errorMsg ==''){

document.getElementById('btnRechargeNow_Click' ).click();

}

else {

document.getElementById('lblErrorMsg')。innerHTML = ShowMessage(errorMsg);

返回false;

}

}

Inside a form I am using a textbox as "Mobile no" and i want to validate that textbox in different different tabs because i am calling the same form in all the tabs:
the tabs are:
1.Prepaid tab
2.Postpaid tab
3.Dth tab
4.data card tab

now when user navigate to first tab,second tab or fourth tab the mobile no textbox should accept only 10 digit but when fourth tab is called it should accept any no of digit

What I have tried:

function IsNumeric(e) {
var specialKeys = new Array();
specialKeys.push(8); //Backspace
var keyCode = e.which ? e.which : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
document.getElementById("error").style.display = ret ? "none" : "inline";
return ret;
}
function ValidateRecharge(rdvalue) {
debugger;
var MobileNo = document.getElementById("txtMobileNo").value;
var amt = document.getElementById("txtAmount").value;
var errorMsg = '';
if(errorMsg==''){
if (MobileNo == "") {
errorMsg += "Please Enter Mobile No.|";
}
//else {
// if (MobileNo.length < 10 || MobileNo.length > 10) {
// errorMsg += "Mobile No. is not valid, Please Enter 10 Digit Mobile No.|";
// }
//}
if (amt == "") {
errorMsg += "Please Enter Amount.|";
}
}

if (errorMsg == '') {
document.getElementById('btnRechargeNow_Click').click();
}
else {
document.getElementById('lblErrorMsg').innerHTML = ShowMessage(errorMsg);
return false;
}
}

推荐答案

任何尝试使用这种方式的标签注定要失败。选项卡是由浏览器实现的,它们不是Web标准的一部分,因此无法知道或控制其他选项卡中发生的事情。
Any attempt to work with tabs in this way is doomed to fail. Tabs are something implemented by the browser, they are not part of web standards so there is no way of knowing or controlling what happens in other tabs.


这篇关于如何在不同的不同选项卡中验证单个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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