Forum Moderators: coopster
e.g.:
[pre]
<?
function x() {
if ($click == 1) {
echo "<br /><table><tr>NewRow</tr></table>";
}
}
?>
<body>
<a href="<? $click = 1; ?>">#*$!x</a>
<? x(); ?>
</body>
[/pre] G.
It seems that you are confusing JavaScript and PHP - PHP is a server side lanugage and there is no "onClick" event handlers as there are in JavaScript - a client-side scripting language.
First, make sure your server supports PHP. Upload your files onto the server. PHP is run on the server, not your local machine (like JavaScript).
Your function x is valid, but will never be used, because this line is invalid:
This line would just display a broken link. You seem to expect the clicking of this link to set the variable click to equal 1. That's not how PHP works.<a href="<? $click = 1; ?>">#*$!x</a>
In PHP, we have to submit a new request to the server every time we want something to happen. Try something like this:
<table>
<?php
// writes the first row no matter what.
echo "<tr><td>This is your first row.</td></tr>";// if $click is not set, end the table and display a link.
if (!isset($_REQUEST['click'])) {
echo "</table>";
echo "<a href='?click=1'>Add new Row</a>";
}
// if $click is set, display the second row, then end the table.
else {
echo "<tr><td>This is your second row.</td></tr>";
echo "</table>";
}
?>
If every <input> have same id can I insert them to the databese?
I hope this helped you, please reply with questions/comments/concerns.
in each new row too is possible do that, beacause I think this will be invalidecho "<a href='?click=1'>Add new Row</a>";
[pre]...
else {
echo "<tr><td>This is your second row.</td></tr>";
[b] echo "<a href='?click=1'>Add new Row</a>"; [/b]
echo "</table>";
}
[/pre]
Thank you.
G.
[pre]
<table>
<?php
[i]//If the defRepeat isn't set the value is 1 (1 row)[/i]
if (!isset ($defRepeat)) {
$defRepeat = 1;
}
for ($repeat = 1; $repeat <= $defRepeat; $repeat++) {
echo "<tr><td> Row content</td>"; [i]// The contet of the row[/i]
[i]// the link is displayed just on the last row[/i]
if ($repeat == $defRepeat) {
[i]// The link will add allways one more row [b]$defRepeat+1[/b][/i]
echo ("<td><a href=\"?defRepeat=".($defRepeat + 1)."\">Add New Row</a>");
[i]// The remove link will show if there are more then one row[/i]
if ($defRepeat > 1) {
echo ("<br /><a href=\"?defRepeat=".($defRepeat - 1)."\">Remove Row</a>");
}
echo ("</td>");
}
}
?>
</table>
[/pre]
G.
One way or another you are going to have to use javascript to do this without a form submit. You can either set the cookie manually with javascript or you can use an asynchronous call to a server-side script to save certain data into sessions or cookies.
[pre]
<?
$oneHour = (mktime(date('h')+1));
$oneHour = date('r',$oneHour); function restoreValue($thisID, $defValue) {
if (isset ($_COOKIE[$thisID])) {
echo $_COOKIE[$thisID];
} else {
echo $defValue;
}
}
?>
<script type="text/javascript">
function setcookie(Cname, Cvalue) {
var expire = "<?php echo $oneHour; ?>";
document.cookie = Cname+"="+Cvalue+"; expires="+expire+"; path=/";
}
</script>
<form>
<input name="Description" id="Description" type="text" value="<?php restoreValue('Popis','The description field');?>" onchange="setcookie(this.id, this.value);"/>
[/pre]
How can I fix this thing?
The page is UTF-8:
[pre]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
[/pre]