Jump to content

heres what i need


h3ktlk

Recommended Posts

right now im using a java script that sets an array..  example below:

 

<script language="Javascript">

var states = new Array("Alabama","Alaska","American Samoa","Arizona","Arkansas","California",

"Colorado","Connecticut","Delaware","District of Columbia",

"Federated States of Micronesia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois",

"Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine",

"Marshall Islands","Maryland","Massachusetts","Michigan","Minnesota","Mississippi",

"Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico",

"New York","North Carolina","North Dakota",

"Northern Mariana Islands","Ohio","Oklahoma","Oregon","Palau","Pennsylvania","Puerto Rico",

"Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont",

"Virgin Islands","Virginia","Washington","West Virginia","Wisconsin","Wyoming",

"Armed Forces Africa","Armed Forces Americas","Armed Forces Canada",

"Armed Forces Europe","Armed Forces Middle East","Armed Forces Pacific");

new AutoSuggest(document.getElementById('firstname'),states);

</script>

 

can i use php and sql to pull the array and put it in the java ?

 

 

 

Link to comment
Share on other sites

<script type="text/javascript">
<?php
  $sql = "SELECT name FROM states ORDER BY NAME";
  $states = array();
  if($result = mysql_query($sql)){
    while($state = mysql_fetch_assoc($result))
      $states[] = $state['name'];
    print 'var states = ["'.implode('","',$states).'];';
    print "\nnew AutoSuggest(document.getElementById('firstname'),states);"
  }
?>
</script>

 

if you are running PHP5+, instead of

    print 'var states = ["'.implode('","',$states).'];';

use  this:

    print 'var states = '.json_encode($states).';';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.