Hide controls when form loads

R

RudiH

Hi,
How can you hide controls, e.g. labels, text boxes etc, when a form is
loaded.
I've written the function below
function HideControls()
{
document.ApplicationForm.txtFrom.style.visibility='hidden';
document.ApplicationForm.txtTo.style.visibility='hidden';
}
and call this function within the <form onload="HideControls()"; ...> tag.
But it doesn't seem to work as expected.
Can somebody help?
Thanks

--
 
K

Kevin Spencer

Try not putting the code into a function, but at the bottom of the form,
just before the </form> tag. The form element doesn't have an "onload"
event. Often, putting such an event handler in the body "onload" event
doesn't work, due to the fact that an HTML document is often loaded in
"chunks" from the server. But any JavaScript code that is not inside a
function is executed immediately upon the loading of the page.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
S

Stefan B Rusynko

Or scrap the script (if you are not going to make them visible w/ another script call) and just add the fields as std hidden form
fields
<input type="hidden" name="txtFrom" value="xxxxx">




| Try not putting the code into a function, but at the bottom of the form,
| just before the </form> tag. The form element doesn't have an "onload"
| event. Often, putting such an event handler in the body "onload" event
| doesn't work, due to the fact that an HTML document is often loaded in
| "chunks" from the server. But any JavaScript code that is not inside a
| function is executed immediately upon the loading of the page.
|
| --
| HTH,
|
| Kevin Spencer
| Microsoft MVP
| .Net Developer
| Ambiguity has a certain quality to it.
|
| | > Hi,
| > How can you hide controls, e.g. labels, text boxes etc, when a form is
| > loaded.
| > I've written the function below
| > function HideControls()
| > {
| > document.ApplicationForm.txtFrom.style.visibility='hidden';
| > document.ApplicationForm.txtTo.style.visibility='hidden';
| > }
| > and call this function within the <form onload="HideControls()"; ...> tag.
| > But it doesn't seem to work as expected.
| > Can somebody help?
| > Thanks
| >
| > --
| >
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top