I am trying something like this:
var areaOption=document.getElementById("<?php echo @$_POST['annonsera_name']?>"); areaOption.selected=true;
Also I have tried this, but it only alerts a BLANK alert-box:
alert (<?php echo $test;?>); // I have tried this with quotes, double-quotes, etc... no luck
Am I thinking completely wrong here?
Some PHP code:
<?php $test = "Hello World!"; ?>
In your second example, you are missing quotes around the string (so H is interpreted as a variable - which you didn't set).
alert (<?php echo "'H'";?>);
alert ('<?php echo "H";?>');
You should be able to check the JS that is generated just looking at the code. Of course, if the JS relies on some PHP variables, they need to be instanciated before the JS is output.
<?php $test = 'Hello world'; ?> <html> <body> <script> alert('<?php echo $test; ?>'); </script> </body> </html>
will work but
<html> <body> <script> alert('<?php echo $test; ?>'); </script> </body> </html> <?php $test = 'Hello world'; ?>
@$_POST indicates that you have received (or are expecting) errors - check your generated source to see if the value was output correctly. Otherwise
document.getElementById will fail and you'd get no output.
alert("Delete entry <? echo $row['id']; ?> ")
If your extension is js, php will not work in that file.
The reason being, php parses on files that it is supposed to. The file types that php will parse are configured in httpd.conf using AddType commands (or directives, whatever they are called).
So you have 3 options:
- add filetype js to the list of files php will parse (BAD, VERY BAD)
- make the script inline to some php file
rename the file to script.js.php, and at the beginning of the file, specify the content type, like so:
People are also looking for solutions of the problem: a non well formed numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.