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