I have a table in HTML coded inside PHP, which has 3 editable text boxes for the user to edit and a submit button. My code looks as follows:
<html>
<head>
<title>test</title>
</head>
<body>
<?php
echo "<table cellpadding=10 cellspacing=0 border=1>";
echo "<tr><th><b>First Name</b></th><th><b>Surname</b></th><th><b>Favourite Colour</b></th></tr>";
echo "<tr>";
echo "<td><input type=\"text\" name=\"t1\" size=\"25\" value=\"text 1\" /></td>";
echo "<td><input type=\"text\" name=\"t2\" size=\"25\" value=\"text 2\" /></td>";
echo "<td><input type=\"text\" name=\"t3\" size=\"25\" value=\"text 3\" /></td>";
echo "</tr>";
echo "</table>";
echo "<br /><br />";
?>
<form method=post action=display.php>
<input type="hidden" name="text1" value="">
<input type="hidden" name="text2" value="">
<input type="hidden" name="text3" value="]">
<input type="submit" name="submit" value="send">
</form>
</body>
</html>
Inside my form, I want to set the value="", to the value the user has entered above for each respective box. I'm not sure how to do this.
Use Javascript for that.
<script>
document.getElementsByName("text1").value = document.getElementsByName("t1").value;
document.getElementsByName("text2").value = document.getElementsByName("t2").value;
document.getElementsByName("text3").value = document.getElementsByName("t3").value;
</script>