client side validation with javascript
<input type="text" id="txtInputTB1"/> ensure your form has the following set for it's onsubmit event:<form onsubmit="validateInputs();"> now, define that function in javascript: function validateInputs()
{
//get a reference to that textbox:
var txtInput = document.getElementById("txtInputTB1");
//check its value
if(txtInput.value == "")
{
//do something if it is empty
alert("Please enter a value for the text input.");
return false;
}
return true;
}
<input type="text" id="txtInputTB1"/> ensure your form has the following set for it's onsubmit event:<form onsubmit="validateInputs();"> now, define that function in javascript: function validateInputs()
{
//get a reference to that textbox:
var txtInput = document.getElementById("txtInputTB1");
//check its value
if(txtInput.value == "")
{
//do something if it is empty
alert("Please enter a value for the text input.");
return false;
}
return true;
}
解决方案 »
- 中国风的IE9 Demo很给力!
- 关于同一页面 动态创建的多IFRAME切换后 textbox 的焦点无法聚焦的问题
- javaScript没有响应的问题
- document.body.clientWidth显示问题
- 随便一个网页,在地址栏贴上下面代码,你会发现很有意思的现象.呵呵
- 怎么获取点击 "media Player 控件"中的停止按钮事件
- 我用框架引用另一框架htm文件里面的表格内容,为什么引用不了?解决马上给分!
- windows.oen方法中宽度与高度能否与调用的文件一致?
- 很奇怪的问题:设置了框架水平滚动条始终显示,还是不显示.只到不够显示文字时才出现.
- 请问JS中如何加入ASP程序以便打开数据库取得信息再显示出来?
- 下拉选和单选的的组合问题
- trList[i+1].cells(0).innerText = getItem(arrText[startline + i], 1);哪错了?
<!--
var g_isPostBack = false;window.onbeforeunload = function ()
{
if( g_isPostBack == true )
return; // Let the page unload if ( window.event )
window.event.returnValue = 'You will lose any unsaved changes!'; // IE
else
return 'You will lose any unsaved changes!'; // FX
}
// -->
</script>private void Page_Load(object sender, System.EventArgs e)
{
RegisterOnSubmitStatement("OnSubmitScript", "g_isPostBack = true;");
}