views:

61

answers:

1

I want to do this

<?php
$dropDown = "<select><option value=\"0\">1-50</option><option value=\"50\">51-100</option><option value=\"100\">151-200</option></select>";

?>    
<html>    
<head>
</head>
<body bgcolor="333333">
<script language="javascript">

<!--
var params = new Object();
params.dropDown = <?php print $dropDown; ?>;

</script> 
</script>
</body>
</html>

but it gives error. Whys that?

+5  A: 

You're missing quotes? Basically, what you're writing here evaluates to

params.dropDown = <select><option value=\"0\">1-50</option><option value=\"50\">51-100</option><option value=\"100\">151-200</option></select>;

On a side note, <?= is more elegant than <?php print.

EboMike
Also hasn't closed the HTML comment in the script `<!-- -->` and there are two closing script tags.
Sean Hogan
`<?=` might be more elegant to you, but depending on settings it may not work (with `short_open_tags` off), so for portable / public code you should never use it.
Wrikken
Great point, Wrikken. Thanks!
EboMike
No its the <even if I use $dropDown = "<hi>"; it wont workbut only $dropdown = "hi"; works.i think i need to iuse htmlentities or something in php...not sure