i've made form below. possible make when user enters number of fields, example 6, table below has 6 rows. great if possible make without submit button (so trigger action exiting text input box).
here html code of form:
<fieldset> <legend>student information</legend> number of fields: <input type="text"><br /> total number of characters: <input type="text"> <br> <br> <table border="1"> <th></th> <th>field</th> <th>number of characters</th> <tr> <td>1</td> <td><input type="text"></td> <td><input type="text"></td> </tr> <tr> <td>2</td> <td><input type="text"></td> <td><input type="text"></td> </tr> </table> </fieldset>
if not possible (without submit button), in way accomplish same result? thank and/or suggestions.
okay here post script require
<?php $rows=2; if(isset($_post['submit'])) { if($_post['submit']=='update') { if(isset($_post['rows'])) $rows=max($rows, intval($_post['rows'])); // minimum 2 rows } else { // process posted data here // reset post or jump page $_post=array(); //header("location:index.php"); //exit(); } } ?> <form method="post"> <fieldset> <legend>student information</legend> number of fields: <input type="text" name="rows" value="<?php echo $rows; ?>"><br /> total number of characters: <input type="text"> <input type="submit" name="submit" value="update"/> <br> <br> <table border="1"> <th></th> <th>field</th> <th>number of characters</th> <?php for($loop=1;$loop<=$rows;$loop++) { echo '<tr>'; echo '<td>'.$loop.'</td>'; echo '<td><input name="field['.$loop.']" value="'.$_post['field'][$loop].'" /></td>'; echo '<td><input name="chars['.$loop.']" value="'.$_post['chars'][$loop].'" /></td>'; echo '</tr>'; } ?> </table> <input type="submit" name="submit" value="submit"/> </fieldset> </form>
it default 2 rows (minimum), , retain data when update rows.
if rows reduced, end ones disappear
Comments
Post a Comment