views:

45

answers:

2

Hey guys,

So I have an .aspx page loading up and populating drop downs based on a lookup table in the database. What we want is for the user to be able to configure which of these values comes defaulted by specifying that value in a drop down somewhere else in the app.

Now, it's easy to default the "first" value, or something like that, but we want this to act differently. Is there a JavaScript function that can run immediately after onLoad (so the drop downs are populated already), that can go through the drop down and make one of those default so it looks like the page is loading with that set as default and people don't realize the workaround? (weird masking, etc.)

I'm not TOO experienced with JavaScript so something like this may already exist.

Here is an example of how we add the dropdown control to the page, in case you guys even need that.

With CType(.AddControl(New Controls.ComboBox("CodeId", "../../../../CodeId", "Code")), Controls.ComboBox)
                            .ForceSelection = True
                            .ValueField = "LookupID"
                            .DisplayField = "LookupDesc"
                            .Validate.AllowBlank = False
                            .ForceSelection = True
                            .ReadOnly = EditControl.IsFieldReadOnly(10580)
                            .BindData(Model.Codes)
                        End With 

Thanks guys!

-Scott

+1  A: 

You need an onReady event, like what jQuery provides: http://api.jquery.com/ready/. It will run when the page content is ready to be manipulated.

SimpleCoder
We run everything in ExtJS at the moment. Is there anything that comes with Ext that is similar? Or anything in basic Javascript that would work the same way?
Scott
See what @João Gala Louros posted
SimpleCoder
+3  A: 

Since you are using ExtJs you can do something like:

Ext.onReady(function(){

   //place your code here

});

This may solve your problem

João Gala Louros