Php to js:what right way of doing it?

i have php file as follows


<script src="array1.js" language="javascript"> </script>

<form action="#" method="">
<select name="how_many">
<option value="1">one</option>
<option value="1">one</option>
</select>
<input type="submit" value="submit" />

</form>
<? 
// Search for the data 

// Make an array of the data you want to output to the javascript 
$details = array( 
            'Firstname' => 'Bill', 
            'Lastname' => 'Gates', 
            'Email' => 'bill@gates.com' 
            ); 

// This converts it from a PHP array to a javascript array 
function phpArrayToJsArray($name,$array,$prePend='var ') { 
   if (is_array($array)) { 
       $result = $name.' = new Array();'."\
"; 
       foreach ($array as $key => $value) { 
           $result .= phpArrayToJsArray($name.'["'.$key.'"]',str_replace("\\r\
",'\
', $value),''); 
       } 
   } else { 
       $result = $name.' = "'.$array.'";'."\
"; 
   } 
   return $prePend.$result; 
} 

// Create the javascript array then print it 
$data = phpArrayToJsArray('Data',$details); 
 //print $data;
?> 

<div onclick="propFest(<?php print $data; ?>);">TESTING</div>

and array1.js as

function propFest(ob){ 
 var val="",pr=""; 

 for(var prop in ob){ 
  pr=prop; 
  val=ob[prop]; 
  alert(pr);
 } 

} 

i am not javascript coder…so bit confused…
rather than hardcoding parameters to javascript function i am planning to pas it as array to js…

so what is right way to do ,what i am trying to do now?

plus,
2.How can i pass selected value from drop down through an array normally i use to do as
onclick='functionname(fieldname.value…)
but seems like it wont work here
array(
‘fieldname’ => ?,

please help

i solved the earlier part…

now i am stucked in this

<form action="#" method=""> <select name="how_many"> <option value="1">one</option> <option value="1">one</option> </select> <input type="submit" value="submit" />  </form>

$details = array(             'Firstname' => 'Bill',             'Lastname' => 'Gates',             'Email' => 'bill@gates.com'             );  

 

is there any way i can get the selected value of select field and send it as new element of array ie
‘Email’ => ‘bill@gates.com’,‘how_many’=>$how_many; );

i think it could be done using ajax
i called get_value.php using ajax on change event of select
$content_type = ( isset($_GET[‘content_type’]) ) ? (int) $_GET[‘content_type’] : 0;

echo $content_type;

but i couldnot get to assign it to $how_many php variable
any help?