Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method to run after page load

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Guys,
I need to add some items to a ListBox control on my page but I want to do it on the client side with a JavaScript function. The items that will be added to the control will be collected on the server, on the Page_Load event, and passed to the JavaScript function that would do the actual adding. So, I need some sort of client-side Page_Load event - a javascript function that would run everytime the page loads - but I'm not sure how to implement it. Can anyone tell me how to do this?

It may seem that what I'm doing doesn't make sense but it does. You see, I need to add a few leading spaces to some of the items of the list box for aligning purposes. Adding the leading spaces from the server doesn't work because the spaces get trimmed. I tried adding & nbsp; (without the space between & and n) but the actual string "& nbsp;" (no space) shows up on the list box, rather than an actual space.

I found, however, that when an item with leading spaces is added to the list box through JavaScript code on the client, the leading spaces do show up. So, what I want to do is collect the items on the server, and add them on the client. For this purpose, I need a JavaScript function that would run after the Page_Load event, but before the page is displayed to the user. Can anybody help me out?

Thanks.

JC

We don't see things how they are; we see them how we are.
 

Run it using the onload event.

If need be you can hide the list box, make your changes, and then show it again.
 
theboyhope,

I'm new to javascript and I don't how to implement events in it. How do I wire up the onload event? Thanks in advance.

JC

We don't see things how they are; we see them how we are.
 

There are a few ways you can do it. Here's one of them:
Code:
window.onload = function() {

 ... Your code ...
 .................

}

HTH.
 
Another way is:
<html>
<head>
<script>
...
function myfunction(){
...
}
...
</script>
</head>

<body onload='myfunction()'>
...
</body>
</html>
 
Thanks Guys...

JC

We don't see things how they are; we see them how we are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top