问题描述
我在asp.net应用程序中使用了两个文本框。我想在buuton点击上比较这两个值。如何检查两个文本框值并使用javascript显示警告消息以及如何在按钮点击事件上调用该功能。
如果有的话一个人知道这个帮助我。
问候
Nanda Kishore.CH
Hi,
I used Two textboxes in my asp.net application. i want to compare that two values on buuton click. How to Check that two textbox values and display alert message using javascript and how to call that function on button click event.
If any one know about this Help me.
Regards
Nanda Kishore.CH
推荐答案
<script type="text/javascript" language="javascript">
function ValidateForm()
{
var Form=document.getElementById('frmDemo');
alert(Form.txtbox1.value);
alert(Form.txtbox2.value);
if(parseFloat(Form.txtbox1.value)<parseFloat(Form.txtbox2.value))
{
alert('hello all');
document.getElementById('txtbox1').focus();
return false;
}
//or
if(parseFloat(Form.txtbox1.value)==parseFloat(Form.txtbox2.value))
{
alert('hello all');
document.getElementById('txtbox1').focus();
return false;
}
//or
if(parseFloat(Form.txtbox1.value)<parseFloat(Form.txtbox2.value))
{
alert('hello all');
document.getElementById('txtbox1').focus();
return false;
}
}
</script>
致电<$ c按钮 OnClientClick
Call ValidateForm()
on Button OnClientClick
<asp:Button ID="BtnSubmit" Text="Proceed" runat="server" OnClientClick="return ValidateForm();"/>
谢谢
Ashish
标记解决方案这是你的答案
Thanks
Ashish
Mark it solution if this is your answer
<asp:button id="btnSave" tabIndex="32" runat="server" CssClass="btn" OnClientClick = "return compare()"Text="Save"></asp:button>
在你的javascipt函数中你现在可以编写如下给出的比较函数
in ur javascipt function now u can write the compare function like given below
<script language="javascript" type="text/javascript">
function compare() {
var txt1 = document.getElementById('txt1').value; // textbox 1 ID is txt1
var txt2 = document.getElementById('txt2').value; // textbox 2 ID is txt2
if (txt1 == txt2) {
alert("both are same");
}
else {
alert("both are different");
}
}
</script>
检查一下。
Check this out.
<asp:button id="Btn_submit" onclientclick="return validate()" onclick="Btn_submit_Click()"/>
这里OnClientClick用于调用javascript函数。这里验证是一个javascript函数。
Here The OnClientClick is used for calling the javascript function. Here validate is a javascript function.
<script type="text/javascript">
function vaildate()
{
...................
...................
....................
}
</script>
这篇关于如何在按钮点击事件上调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!