View Full Version : PHP & Javascript Not Working
dawizman
March 25th, 2003, 12:31
Ok, here is a snippet of my code:
echo "<B>Processor(CPU):</B>";
echo "<SELECT NAME='processor' SIZE='1'>";
while($row = mysql_fetch_array($result_procamd) )
{
echo "<OPTION VALUE=" . $row['price'] . ">" . $row['name'] . "\n";
};
echo "<SCRIPT type=\"text/javascript\">";
echo "var procamd = \"" . $row['price'] . "\"";
echo "document.write (procamd)";
echo "</SCRIPT>";
can anybody see any errors that are not allowing it to display the javascript variable?
HostingMontreal
March 27th, 2003, 18:50
Personally I prefer to use the PHP features that allow me
to write out normal html without using print functions. If
you want, I can try and debug your code, I think I saw a
few errors here and there.
PHP:--------------------------------------------------------------------------------
<B>Processor(CPU):</B>
<SELECT NAME='processor' SIZE='1'>
<?
while($row = mysql_fetch_array($result_procamd) ){
?>
<OPTION VALUE="<?= $row['price'] ?>"><?= $row['name'] ?></option>
<? } ?>
<SCRIPT type="text/javascript">
var procamd = '<?= $row['price'] ?>';
document.write(procamd);
</SCRIPT>
--------------------------------------------------------------------------------
dawizman
March 27th, 2003, 19:54
Thanks, i'll try that.
Cagez
March 27th, 2003, 20:00
You dont need a semi-colon at the end of your while, and the javascript your using is outside of the loop so you'll only get one price printed. If all your using the javascript for is to print the price variable, then you can just echo it out.
echo "<B>Processor(CPU):</B>";
echo "<SELECT NAME='processor' SIZE='1'>";
while($row = mysql_fetch_array($result_procamd) )
{
echo "<OPTION VALUE=" . $row['price'] . ">" . $row['name'] . "\n";
echo $row['price'];
}
dawizman
March 27th, 2003, 23:17
is there any way I can get the javascript variable to change according to which option is selected?
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.