View Full Version : how to insert php code inside javascritp

12-18-2006, 04:03 PM
I've this problem: i've to populate 3 combo box with data that come from 3 different tables in a MySql database, i'm trying to do that using a javascript in the following way but noghing go like i need...any idea ?

<script language="JavaScript">
var i_macro = <?php echo $num_rows; ?>;
document.write("Numero righe Macro: " + i_macro);
var macro_id = new array();
var macro_descrizione = new array();
for($i=0; $i < $num_rows; $i++)
$row = mysql_fetch_array($result);
$macro_id = $row["id_problema"];
echo "<br>".$macro_id."<br>";
$macro_descrizione = $row['tipo_problema'];
echo $macro_descrizione;
macro_id[<?php $i ?>] = <?php $macro_id ?>;
document.write("Macro_id: " + macro_id[<?php $i ?>]);
macro_descrizione[<?php echo $i; ?>"] = <?php $macro_descrizione; ?>;
document.write("Numero righe Macro: " + macro_descrizione[<?php $i; ?>]);

Thanks :thumbsup:

12-18-2006, 04:22 PM

An example. The $options array is the array returned by $row = mysql_fetch_array($result);

FYI: JavaScript is case-sensitive. new array() is wrong, new Array() is correct.


$options = array ('One', 'Two', 'Three', 'Four', 'Five');

$fillSelect = '';
foreach($options as $value)
$fillSelect .= "<OPTION VALUE=\"$value\">$value</OPTION>";


<script type="text/javascript">

function showChoice(nValue){


<select name="anyName" onchange="showChoice(this.value)">
<option value=""> Make a Selection </option>
<?php echo $fillSelect; ?>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum