Page 1 of 1
why doesn't this work?
Posted: Thu Jun 12, 2003 9:05 am
by Brakanjan
<?
echo '<script language="Javascript">
document.form1.hidden.value = "Hello";
</script>
<body>
<form name=form1 action=Doit.php method=GET>
<input type=text name=hidden>
</form>
<body>';
?>
I though php was easy!
Why can't I inlcude src="name.js" files in php?
Posted: Thu Jun 12, 2003 9:27 am
by volka
it's not a php problem.
Before giving you the answer a small side-note

php is executed server-side, the browser will only receive the outout. Therefor for the browser there is no difference between your script and the static html-page
Code: Select all
<script language="Javascript">
document.form1.hidden.value = "Hello";
</script>
<body>
<form name=form1 action=Doit.php method=GET>
<input type=text name=hidden>
</form>
<body>
side-note #2 (we're getting closer): always quote the values of properties:
<form name="form1" action="Doit.php" method="GET"> unless you're absolutely sure about what you're doing. It's also nice to close each element you're opening, even those that have no content:
<input type=text name=hidden />
ok, now for the current problem: The script is executed before the form exists, so there is no object document.form1 (yet). Try
Code: Select all
<html>
<body>
<form name="form1" action="Doit.php" method="GET">
<input type="text" name="hidden" />
</form>
<script type="text/javascript">
document.form1.hidden.value = "Hello";
</script>
</body>
</html>
Posted: Thu Jun 12, 2003 9:40 am
by Brakanjan
I should have known....
tx!
Posted: Thu Jun 12, 2003 12:43 pm
by oldtimer
I am still converting from using all php from a mix of php and html.
Ie <tr><td>Hello <? echo $_SESSION['user']; ?></td></tr>
to
echo "<tr><td>Hello $_SESSION['user']</td></tr>";
Posted: Thu Jun 12, 2003 7:51 pm
by Paddy
oldtimer wrote:I am still converting from using all php from a mix of php and html.
Ie <tr><td>Hello <? echo $_SESSION['user']; ?></td></tr>
to
echo "<tr><td>Hello $_SESSION['user']</td></tr>";
String concatenation with the dot. You need to distinguish between php code and strings in the echo statement. Like
echo "<tr><td>Hello ".$_SESSION['user']."</td></tr>";
Posted: Thu Jun 12, 2003 7:53 pm
by oldtimer
Typo on my part. That is how I do it. That is what I get when I have too many things going on at one time

Posted: Thu Jun 12, 2003 7:56 pm
by Paddy
Ah well, maybe someone else will learn from it then.

Posted: Thu Jun 12, 2003 8:38 pm
by oldtimer
We are always learning. I have figured that much out so far.