|
 |
aspx thread: Create javascript array dynamically?
Message #1 by Philo <philo@r...> on Sun, 02 Jun 2002 20:37:26 -0400
|
|
Here's what I'm trying to do:
A web form has a drop down list and a bunch of text boxes. Selecting a
value from the dropdown list populates the text boxes. (Without a round
trip to the webserver)
In ASP I'd build a javascript array with the potential values and call a
function in the onchange event of the dropdownlist to populate the text
boxes.
I can figure everything out except building the array from the database -
how do I do this?
It should end up like:
<HEAD>
<script language="Javascript">
var dataArray = new Array();
dataArray[1]=new Array("name", "date", "age");
dataArray[2]=new Array("name2", "date2", "age2");
etc.
</script>
And I'm sure you can see how I'd dynamically build something like that in
ASP. How do I do it in ASP.Net?
Philo
Message #2 by "John Wormald" <johnswormald@h...> on Tue, 4 Jun 2002 16:12:56
|
|
Philo
One method is to create your dataset server side in XML using
DataSet.GetXml. Set this to the value of an HtmlInputHiddenField. The
dataset in Xml will then be available to you client side. If the field is
called, ClientProdXml do the following in a javascript function client to
load the xml:
xmlProd = new ActiveXObject("MSXML2.DOMDocument");
xmlProd.async = false;
xmlProd.loadXML(document.forms[0].elements['ClientProdXml'].value);
You can now traverse the XML and populate your array.
Another method is to use web service behaviors - check out Steven
Walthers' book, ASP.NET Unleashed Chapter 23. This will show you how to
retrieve arrays of data from the client.
For more info on webservice behavior check out the following url (look out
for spurious characters):
http://msdn.microsoft.com/library/default.asp?
url=/workshop/author/webservice/webservice.asp
Hope this helps.
John
> Here's what I'm trying to do:
A web form has a drop down list and a bunch of text boxes. Selecting a
value from the dropdown list populates the text boxes. (Without a round
trip to the webserver)
In ASP I'd build a javascript array with the potential values and call a
function in the onchange event of the dropdownlist to populate the text
boxes.
I can figure everything out except building the array from the database -
how do I do this?
It should end up like:
<HEAD>
<script language="Javascript">
var dataArray = new Array();
dataArray[1]=new Array("name", "date", "age");
dataArray[2]=new Array("name2", "date2", "age2");
etc.
</script>
And I'm sure you can see how I'd dynamically build something like that in
ASP. How do I do it in ASP.Net?
Philo
|
|
 |