Solved

How do I disable an ImageButton until the web page is completely loaded?

Posted on 2011-10-01
4
309 Views
Last Modified: 2012-05-12
I am working on a web app.  And, I have an ImageButton object that throws an error, if it is clicked before the page load completes.  It is set up, via javascript, as a Calendar button that is tied to an input field.  There is some processing that occurs on the input field that is causing this problem (if the button is clicked prior to completion).  So, I want to know how to disable this ImageButton until the entire page is completely loaded.  I searched around and determined (maybe incorrectly so) that I should do this within the onLoad atrribute of the Body.  Note: this is also where the function is called that is doing the processing that causes the error when the button is clicked prematurely).  I thought that if I start with a disabled imagebutton first, I could reenable it as the final onLoad statement.  But, that hasn't worked so far, as I am getting an error.  Please correct this solution or suggest a different one that works.  I am knowledgeable in C#, but very new to HTML/Javascript, so I need baby step-type solution please.

My current code:
<body onload=populateCurrDate('tbArrDate', 'tbDSDateTime', 'tbALocDateTime', 'tbPLocDateTime'); document.forms[0]btnArrDate.disabled=false;">
where btnArrDate is the ImageButton that I want to enable.  But, I get the following runtime error: 'document.forms.0.btnArrDate' is null or not an object.  But, it is establish later in the <form> ....</form> definition.  And, I thought onload executes after the page is loaded.  If not, what do I use?
0
Comment
Question by:spazjr01
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36898156
<body onload="populateCurrDate('tbArrDate', 'tbDSDateTime', 'tbALocDateTime', 'tbPLocDateTime'); document.getElementsByName('btnArrDate')[0].removeAttribute('disabled');">
0
 

Author Closing Comment

by:spazjr01
ID: 36898163
thanks much.  Worked on first try.
0
 
LVL 7

Expert Comment

by:Slimfinger
ID: 36898168
Shouldn't
   "document.forms[0]btnArrDate"
...be
   "document.forms[0].btnArrDate"
...instead?

I realize this is not an answer, but I am curious what the button does and how it is causing an error.
0
 

Author Comment

by:spazjr01
ID: 36899356
Slimfinger,
You are correct.  That was simply a typo when I posted the question.  My code actually had document.forms[0].btnArrDate.  Sorry for the confusion.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now