Posted by Stefan Mueller on 10/10/24 11:32
> So if you want a text appear depending what you do in another part of the
> form, then you have to use clientside scripts and the solution would be to
> use
>
> document.MyForm.MyBox.value = "some text";
While generating the page with PHP I do some checks and my goal was to write
the results of these checks to a hidden input. At the end I thought I could
read this input box with a JavaScript to decise what to do next.
But now I understand why it's not working.
Therefore I have to write the results of my checks during the generation of
my page within PHP to a PHP variable ($MyPHPVariable) and read this variable
with the JavaScript. But that's my next problem.
How can I read a PHP variable with a JavaScript?
>> PS: To transfer the content of a PHP variable to a JavaScript variable
>> with
>> $MyJSVariable = <?echo $MyPHPVariable; ?>
>> doesn't work. Mozilla Firefox's JavaScript Console says syntax error at
>> '<?'
>> I've to do that within JavaScript. Correct? I'm a little bit surprised
>> why
>> your JavaScript variable has a '$' at the beginning.
>
> var MyJSVariable = <? echo $MyPHPVariable; ?>;
I try the following code on my PHP server but the browser says syntax error
in 'var MyJSVariable = ;'
I guess that '<? echo $MyPHPVariable; ?>' gets translated to nothing because
my PHP variable is empty at the beginning:
Stefan
==========================
<html>
<head>
<script type = "text/javascript">
function PageIsLoaded() {
var MyJSVariable = <? echo $MyPHPVariable; ?>;
alert(MyJSVariable);
}
</script>
</head>
<body onLoad = "PageIsLoaded()">
<?php
$MyPHPVariable = "some text";
?>
</body>
</html>
==========================
Navigation:
[Reply to this message]
|