在字段为空时发出警报 [英] alert when the fields were null
本文介绍了在字段为空时发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我的价值观包括姓名,年龄,性别和国家/地区.
这些字段为空时,我想使用javascript制作警报框.
我的代码是
Hi friends,
I''m having values as name, age, sex and country.
I want to make alert box using javascript when these field were null.
my code is
title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function Checkid ()
{
var name=document.getElementById(''TxtName'');
if(name=="")
{
alert("enter value in name field");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
<asp:TextBox ID="TxtAge" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Sex
</td>
<td>
<asp:RadioButtonList ID="RadioBtn" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
Country
</td>
<td>
<asp:DropDownList ID="Drp1" runat="server">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
<asp:ListItem>France</asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
<asp:ListItem>Gremany</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan=2 align="center">
<asp:Button OnClientClick="Checkid ();" ID="Btn1" Text=" Save " runat="server" />
</td>
</tr>
</table>
</div>
我只想学习Java脚本,请给我建议好的pdf或任何带有示例的链接.
在此先感谢
I just want to learn java script, please suggest me the good pdf or any links with examples.
Thanks in advance
推荐答案
以
开头 http://www.tizag.com/javascriptT/javascriptalert.php [ http://www.w3schools.com/JS/js_popup.asp [
Start with
http://www.tizag.com/javascriptT/javascriptalert.php[^]
http://www.w3schools.com/JS/js_popup.asp[^]
我认为这些链接将为您提供帮助.
http://www.w3schools.com/js/default.asp [ http://www.learn-javascript-tutorial.com/ [此处 a> [ ^ ]
而这里的问题是,您正在检查name
,它是null的对象.这是不正确的.您必须检查像这样的值.
I think these links will help you.
http://www.w3schools.com/js/default.asp[^]
http://www.learn-javascript-tutorial.com/[^]
More here[^]
And here your problem is, you are checkingname
which is object to null. It is not correct. You have to check the value like this.
if(name.value == "")
{
alert("enter value in name field");
}
^ ]
这篇关于在字段为空时发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文