I have a text box control and i have coded its "onblur" event t a Javascript function. I want this javascript function to make visible a checkbox based on comaprison between the textbox being blurred and a hidden textbox on the same page. The javascript is not working. Please help. Here is what I have coded in ASP.NET 2.0 page.
Thanks
Bhushan (<email snipped>)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Check Box Check</title>
<script language="javascript" type="text/javascript">
function CheckBoxCheck()
{
var t1 = document.getElementById("<%=txt1.ClientId %>");
var t2 = document.getElementById("<%=txt2.ClientId %>");
var chk = document.getElementById("<%=chk1.ClientId %>");
var t1Value = 0;
var t2Value = 0;
if ( ( t1.value == "" ) || ( t1.value == null ) || (t1.value == undefined))
{};
else
{
alert('reached 1');
if ( ( t2.value == "" ) || ( t2.value == null ) || (t2.value == undefined))
{};
else
{
t1value = t1.value;
t2value = t2.value;
if (t1value == t2value)
{chk.visible = false;
alert('reached 3')};
else
{chk.visible = true;
alert('reached 4')};
};
};
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt1" runat="server" onblur="CheckBoxCheck()"></asp:TextBox>
<asp:CheckBox ID="chk1" runat="server" Visible="False" />
<asp:TextBox ID="txt2" runat="server" Visible="true">555</asp:TextBox><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
8 8408
Heya, bkarle. Welcome to TSDN!
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
The code I pasted does not do what I want it to do.
What I want it to do is that when I tab away from the textbox (txt1), I want it to automatically compare the values of that textbox with the value in another textbox (txt2) and based on the results of the comparison, make the check box visible (or leave it invisible) .
Currently, the code does not do it. I left a few alerts in there to give you an idea as to how far my code is working.
If you copy and paste the code above into a ASP.NET page, it should give you an idea.
Thanks
Heya, Bhushan.
Currently, the code does not do it. I left a few alerts in there to give you an idea as to how far my code is working.
If you copy and paste the code above into a ASP.NET page, it should give you an idea.
That will be hard for me to set up on my Mac ~_^
Are you getting any alerts? Is the JavaScript generating an error? Is CheckBoxCheck getting evaluated when the textbox loses focus?
I have a text box control and i have coded its "onblur" event t a Javascript function. I want this javascript function to make visible a checkbox based on comaprison between the textbox being blurred and a hidden textbox on the same page. The javascript is not working. Please help. Here is what I have coded in ASP.NET 2.0 page.
Thanks
Bhushan (email removed)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Check Box Check</title>
<script language="javascript" type="text/javascript">
function CheckBoxCheck()
{
var t1 = document.getElementById("<%=txt1.ClientId %>");
var t2 = document.getElementById("<%=txt2.ClientId %>");
var chk = document.getElementById("<%=chk1.ClientId %>");
var t1Value = 0;
var t2Value = 0;
if ( ( t1.value == "" ) || ( t1.value == null ) || (t1.value == undefined))
{};
else
{
alert('reached 1');
if ( ( t2.value == "" ) || ( t2.value == null ) || (t2.value == undefined))
{};
else
{
t1value = t1.value;
t2value = t2.value;
if (t1value == t2value)
{chk.visible = false;
alert('reached 3')};
else
{chk.visible = true;
alert('reached 4')};
};
};
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt1" runat="server" onblur="CheckBoxCheck()"></asp:TextBox>
<asp:CheckBox ID="chk1" runat="server" Visible="False" />
<asp:TextBox ID="txt2" runat="server" Visible="true">555</asp:TextBox><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>
_Bhushan,
Please try this code. It works fine. -
<html xmlns="http://www.w3.org/1999/xhtml" >
-
<head id="Head1" runat="server">
-
<title>Check Box Check</title>
-
-
<script language="javascript" type="text/javascript">
-
function CheckBoxCheck()
-
{
-
//var t1 = document.getElementById("<%=txt1.ClientId %>");
-
//var t2 = document.getElementById("<%=txt2.ClientId %>");
-
//var chk = document.getElementById("<%=chk1.ClientId %>");
-
-
var t1 = document.getElementById('<%=txt1.ClientId %>').value;
-
var t2 = document.getElementById('<%=txt2.ClientId %>').value;
-
var chk = document.getElementById('<%=chk1.ClientId %>');
-
-
var t1Value = 0;
-
var t2Value = 0;
-
-
if ( ( t1 == "" ) || ( t1 == null ) || (t1 == undefined))
-
{};
-
else
-
{
-
alert('reached 1');
-
if ( ( t2 == "" ) || ( t2 == null ) || (t2 == undefined))
-
{};
-
else
-
{
-
t1value = t1;
-
t2value = t2;
-
-
if (t1value == t2value)
-
-
{
-
-
-
document.getElementById('divCheck').style.display="none";
-
alert('reached 3')};
-
-
else
-
-
{
-
-
document.getElementById('divCheck').style.display="block";
-
-
alert('reached 4')};
-
};
-
-
};
-
}
-
</script>
-
-
</head>
-
<body>
-
<form id="form1" runat="server">
-
<div>
-
<asp:TextBox ID="txt1" runat="server" onblur="CheckBoxCheck()"></asp:TextBox>
-
<div id="divCheck" style="display:none " ><asp:CheckBox ID="chk1" runat="server" /></div>
-
<asp:TextBox ID="txt2" runat="server" Visible="true">555</asp:TextBox><br />
-
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
-
</div>
-
</form>
-
</body>
-
</html>
-
Heya, Suezie. Welcome to TSDN!
Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?
You will still need to use [/code] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:
[code=html]
[code=javascript]
[code=php]
and so on.
Thanks!
MODERATOR
Banfa 9,065
Expert Mod 8TB
Hi bkarle,
please note that posting you email address is not allowed on this forum.
Please read the Posting Guidelines for this and other infomation on what can and can't be posted.
Regards
Banfa
Administrator
Thank you everyone. Suezie's suggestion is great. Basically, I was trying to make the serverside control Checkbox visible/invisible in javascript and it was proving diffcult. It was much easier to have a div (a client side control) and control its visibility (using style attibute such as style="display:none" or style="display:block") using javascript.
If anyone wants the code, I can post it later.
Thanks
Bhushan
Hi bkarle,
please note that posting you email address is not allowed on this forum.
Please read the Posting Guidelines for this and other infomation on what can and can't be posted.
Regards
Banfa
Administrator
Hey, you're back! Where have you been?
PS. I removed the email from Suezie's reply too.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Powell |
last post by:
I am having a potential PHP/Javascript/HTML conflict going on in my
code that I simply can't resolve - been wracking my brain for a good
hour over this one and have come up with no good solution.
...
|
by: Dave Blair |
last post by:
Hi,
I have a problem with our intranet, we are planning to install Firefox
instead of Internet Explorer onto some new PCs.
However, we can't get the following JavaScript to work in Firefox and...
|
by: lindsey.crocker |
last post by:
I have a problem calling a framset from javascript - I will explain as
best I can.
I have a site with 2 frames. Left frame contains a javascript menu.
Right frame contains the page and a...
|
by: simo sentissi |
last post by:
Hello
I have a popup window that I would like to keep on top so I am using the
foloowing javascript:
window.onblur = function()
{ setTimeout('self.focus()',100); }
it keeps my popup...
|
by: Muhammad Abdullah |
last post by:
Hi
am having some problems with the javascript confirm.
i have it working fine on one page and it doesnt even pop up at the
other.
The code on the working page is,
private void...
|
by: John |
last post by:
Hi Everyone,
I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement...
|
by: Sculder |
last post by:
Hello,
I'm running into an interesting issue and I wanted to verify it was a bug with Internet Explorer 7.
I have a field that has an javascript onBlur event. When you set focus to the text...
|
by: paulyXvpf |
last post by:
Hello javascript folks,
PROBLEM: Javascript dropdown problem in IE 6 and IE7
DESCRIPTION: menu falls behind a container box on web page
COMMENTS: It works fine in Firefox but not in IE 6/7...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |