spacer
Yehuda Shiran August 27, 2001
Passing an Array to the Dialog Box
Tips: August 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
When passing a parameter by value to the dialog box, the callee can only read the passed parameter, but cannot change it in the caller page. In order to be able to change the caller, you need to pass the parameter by reference. You do this when you pass the address of a variable. There are at least two ways to pass addresses: an array and an object. Let's demonstrate the array passing. In this page (the caller), we define an array a as follows:

<SCRIPT LANGUAGE="JavaScript">
<!--
  var a = new Array;
  a[0]="first";
  a[1]="second";
  a[2]="third";
// -->
</SCRIPT>

And we pass the array a to the dialog box:

window.showModelessDialog('010827a.html',a);
The callee 010827a.html includes the following script:

<SCRIPT LANGUAGE="JavaScript">
<!--
  a = dialogArguments;
  a[0] = "fourth";
// -->
</SCRIPT>

The callee changed the first element of the array and it should be reflected in the caller page. Let's try it. First, let's make sure the array a is as we initialized it: "first,second,third". Now, call 010827a.html to change it:

window.showModelessDialog('010827a.html',a);
Notice how we pass the array a as the second argument of showModelessDialog(). Feel free to close the dialog box. The dialog box already modified a[0], so you should see a modified array: "fourth,second,third".

For more on modal and modeless dialog boxes, go to Column 90, Modal and Modeless Dialog Boxes.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends