Re: Stuffing a PHP array variable into a javascript array variable

From: Date: Fri, 05 Jan 2001 09:54:12 +0000
Subject: Re: Stuffing a PHP array variable into a javascript array variable
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-4828@lists.php.net to get a copy of this message
It is possible to do this - the only successful way that I have found though is to serialise the array and populate a new one for javascript. A thought occurs to me though. Why not populate the client name list from your table, and then create an 'on update' event for it which will 1)run the php script to pull out the rest of the information from the table(s) only for that client and then 2)call PHP_SELF to display this data in a pseudo dynamic style on your form. Tom Jason Hoover wrote: > Is it possible to stuff a php array variable into a javascript array > variable so I can loop through it to display things dynamically on my page? > > example: > > I have a form that has a data-driven select list that a user can select a > clientname from. Upon doing so, I run a javascript function called > displayValues() that populates a number of text boxes in this form with > data-driven information based on the id of the client name selected. > > I think if there was a way to stuff my $array variable into a javascript > array variable, I would be able to pull this off. > > Any Ideas? > > SAMPLE CODE: > > //GRAB DATA > $sql = "SELECT * FROM CLIENT"; > $connection = mysql_connect(localhost); > $result = mysql_db_query($database, $sql, $connection); > $numClients = mysql_num_rows($result); > > // DEFINE VARIABLES > $array = mysql_fetch_array($result); > $clientID = $array[ID]; > $address1 = $array[ADDRESS1]; > $address2 = $array[ADDRESS2]; > $city = $array[CITY]; > $state = $array[STATE]; > $zip = $array[ZIPCODE]; > $phone = $array[PHONE1]; > $email = $array[EMAIL]; > $contact = $array[MAINCONTACT]; > $title = $array[MAINCONTACTTITLE]; > > echo " > <SCRIPT LANGUAGE=\"JavaScript\"> > <!-- > function displayValues() > { > for(count=0; count<$numClients; count++) > { > if (document.form.clientName.selectedIndex == 0) > { > clientAddress1 = > document.form.clientName.options.text = ''; > clientAddress2 = > document.form.clientName.options.text = ''; > clientCity = > document.form.clientName.options.text = ''; > clientState = > document.form.clientName.options.text = ''; > clientZip = > document.form.clientName.options.text = ''; > clientPhone = > document.form.clientName.options.text = ''; > clientEmail = > document.form.clientName.options.text = ''; > clientContact = > document.form.clientName.options.text = ''; > clientTitle = > document.form.clientName.options.text = ''; > }else{ > document.form.clientName.selectedIndex == count > clientAddress1 = > document.form.clientName.options.text = '$address1'; > clientAddress2 = > document.form.clientName.options.text = '$address2'; > clientCity = > document.form.clientName.options.text = '$city'; > clientState = > document.form.clientName.options.text = '$state'; > clientZip = > document.form.clientName.options.text = '$zip'; > clientPhone = > document.form.clientName.options.text = '$phone'; > clientEmail = > document.form.clientName.options.text = '$email'; > clientContact = > document.form.clientName.options.text = '$contact'; > clientTitle = > document.form.clientName.options.text = '$title'; > } > > } > document.form.address1.value = \"\" + clientAddress1 + \"\" > document.form.address2.value = \"\" + clientAddress2 + \"\" > document.form.city.value = \"\" + clientCity + \"\" > document.form.state.value = \"\" + clientState + \"\" > document.form.zip.value = \"\" + clientZip + \"\" > document.form.phone.value = \"\" + clientPhone + \"\" > document.form.email.value = \"\" + clientEmail + \"\" > document.form.contact.value = \"\" + clientContact + \"\" > document.form.title.value = \"\" + clientTitle + \"\" > > > } > //--> > </SCRIPT> > "; > > ?> > </head> > <body> > <? > ////////////////// FORM WOULD GO HERE ///////////////////// > > ////////////////////FORM: END ///////////////////////////////////// > ?> > </body> > </html> > > Jason Hoover > > Entolo > 2299 Territorial Road > St. Paul, MN 55114 > Phone: 612.847.8022 > Fax: 651.642.1600 > jhoover@entolo.com > www.entolo.com > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.windows (#4828) next »