<?
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?
why doesn't this work?
Moderator: General Moderators
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-pageside-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
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>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>-
Paddy
- Forum Contributor
- Posts: 244
- Joined: Wed Jun 11, 2003 8:16 pm
- Location: Hobart, Tas, Aussie
- Contact:
String concatenation with the dot. You need to distinguish between php code and strings in the echo statement. Likeoldtimer 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>";
echo "<tr><td>Hello ".$_SESSION['user']."</td></tr>";