473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP.NET 2.0 Javascript onblur problem

3
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>
Jul 11 '07 #1
8 8408
pbmods
5,821 Expert 4TB
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.
Jul 12 '07 #2
bkarle
3
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
Jul 12 '07 #3
pbmods
5,821 Expert 4TB
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?
Jul 12 '07 #4
Suezie
1
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.
Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head id="Head1" runat="server">
  3. <title>Check Box Check</title>
  4.  
  5. <script language="javascript" type="text/javascript">
  6. function CheckBoxCheck()
  7. {
  8. //var t1 = document.getElementById("<%=txt1.ClientId %>");
  9. //var t2 = document.getElementById("<%=txt2.ClientId %>");
  10. //var chk = document.getElementById("<%=chk1.ClientId %>");
  11.  
  12. var t1 = document.getElementById('<%=txt1.ClientId %>').value;
  13. var t2 = document.getElementById('<%=txt2.ClientId %>').value;
  14. var chk = document.getElementById('<%=chk1.ClientId %>');
  15.  
  16. var t1Value = 0;
  17. var t2Value = 0;
  18.  
  19. if ( ( t1 == "" ) || ( t1 == null ) || (t1 == undefined))
  20. {};
  21. else
  22. {
  23. alert('reached 1');
  24. if ( ( t2 == "" ) || ( t2 == null ) || (t2 == undefined))
  25. {};
  26. else
  27. t1value = t1;
  28. t2value = t2;
  29.  
  30. if (t1value == t2value)
  31.  
  32. {
  33.  
  34.  
  35. document.getElementById('divCheck').style.display="none";
  36. alert('reached 3')};
  37.  
  38. else 
  39.  
  40. {
  41.  
  42. document.getElementById('divCheck').style.display="block";
  43.  
  44. alert('reached 4')};
  45. };
  46.  
  47. };
  48. }
  49. </script>
  50.  
  51. </head>
  52. <body>
  53. <form id="form1" runat="server">
  54. <div>
  55. <asp:TextBox ID="txt1" runat="server" onblur="CheckBoxCheck()"></asp:TextBox>
  56. <div id="divCheck" style="display:none " ><asp:CheckBox ID="chk1" runat="server" /></div>
  57. <asp:TextBox ID="txt2" runat="server" Visible="true">555</asp:TextBox><br />
  58. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  59. </div>
  60. </form>
  61. </body>
  62. </html>
  63.  
Jul 12 '07 #5
pbmods
5,821 Expert 4TB
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
Jul 12 '07 #6
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
Jul 13 '07 #7
bkarle
3
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
Jul 13 '07 #8
acoder
16,027 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
Hey, you're back! Where have you been?

PS. I removed the email from Suezie's reply too.
Jul 14 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

16
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. ...
4
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...
1
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...
0
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...
1
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...
7
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...
12
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...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.