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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tring to use PHP to query db and pass variables into JavaScript!

Status
Not open for further replies.

Are8Jay

Programmer
Sep 22, 2002
17
0
0
US
I need to fill the array in JavaScript at runtime. Here is an example of the array hard coded or(static) I need dynamic way to fill in the array pending on what images are in the gallery selected:
Code:
<script>
Book_Image_Sources=new Array(
"gallery/DSC00002.png","",
"gallery/DSC00003.png","",
"gallery/DSC00004.png","",
"gallery/DSC00005.png","",
"gallery/DSC00006.png","",
"gallery/DSC00007.png","",
"gallery/DSC00008.png","",
"gallery/DSC00009.png","",
"gallery/DSC00010.png",""
);
</script>

I'm querying a db to get the slideshow images paths and placeing them into a form:
Code:
<form name="slideShow">
<input type="hidden" name="info" value="<?php echo $info_string; ?>" >
</form>

Then, call in the JavaScript for slideshow and declaring global variable and I need to get the "$info_string" into the JavaScript array. This is what's NOT working.

Code:
<script>
var str = new String;

str = document.slideShow.info.value;

// to remove any trailing commas
str = str.substring(0, (str.length-1) );	

Book_Image_Sources=new Array(str);
</script>

Any help would be greatly appreciated!
 

If you have access to server-side coding (which I assume you do to get the DB stuff working), then why don't you just loop around and populate the array paths directly? Why have the extra step of populating a form field?

If you do still want to go the "extra work for yourself" route, you'll have to explain the format the the "$info_string" variable.

Dan
 
I do have access to the server-side. I'm not sure on how to do that?
Code:
<script language="javascript">
Book_Image_Sources=new Array(

<?php
while($row=mysql_fetch_array($sql))
{
   $img_path=$row['img_path'];
   $img_alt=$row['img_alt'];
?>
"<?php echo $img_path; ?>","<?php echo $img_alt; ?>",
<?php
} // end php while loop
?>
); // end new array declaration
</script>

This is not working in either.

HELP!



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top