Hello,
I have a big long form that my users have to fill out and would like to ease their burden.
I'm using several lines of repetitious code that collects info about the appliances used in the user's home, including wattage, quantity, etc. The data in many of the cells is predictable and it would be a time saver if I could preload that data in the cell when the user moves to that cell. For example, I'd like to have a blank form, but when the user puts the cursor into the "dishwasher wattage" cell, it would automatically fill with the value "300". This value could then be changed by the user if it's incorrect.
If that's not possible, I'd like for the values to already be in the cells when the form is loaded, and have the cell data editable by the user.
Below is a segment of the code (the start of the form and the first few rows of input cells)...
<html>
<?
FORM ACTION="loadCalc.php" METHOD="post">
<TABLE BORDER="2" FRAME="box" RULES="rows" BGCOLOR="#EEEEEE">
<CAPTION><h2>LOAD CALCULATOR</h2></CAPTION>
<COLGROUP align="left">
<COLGROUP align="center">
<COLGROUP align="center">
<COLGROUP align="center">
<COLGROUP align="center">
<TR><TH><CENTER>Appliance Name</CENTER></TH>
<TH width=100>Quantity</TH>
<TH width=100>Watts</TH>
<TH width=100>hrs/day (Summer)</TH>
<TH width=100>hrs/day (Winter)</TH></TR>
<TBODY>
<TR><TD>Refrigerator</TD>
<TD><INPUT type="text" name="numFridges" value="" SIZE=4></TD>
<TD><INPUT type="text" name="fridgeWatts" value="" SIZE=4></TD>
<TD><INPUT type="text" name="summ_0" value=""SIZE=4></TD>
<TD><INPUT type="text" name="wint_0" value="" SIZE=4></TD></TR>
<TR><TD>Light Bulbs</TD>
<TD><INPUT type="text" name="numLights" value="" SIZE=4></TD>
<TD><INPUT type="text" name="lightWatts" value="" SIZE=4></TD>
<TD><INPUT type="text" name="summ_1" value="" SIZE=4></TD>
<TD><INPUT type="text" name="wint_1" value="" SIZE=4></TD></TR>
<TR><TD>Computer</TD>
<TD><INPUT type="text" name="numComps" value="" SIZE=4></TD>
<TD><INPUT type="text" name="compWatts" value="" SIZE=4></TD>
<TD><INPUT type="text" name="summ_2" value="" SIZE=4></TD>
<TD><INPUT type="text" name="wint_2" value="" SIZE=4></TD></TR>
Thanks, any help would be appreciated.
Preloading table cells
Moderator: General Moderators
You'll need to store the data some place. It will have to be retrieved. Assuming you know how to do that all you have to do is something like this:
Code: Select all
<input type="e;text"e; name="e;telephone"e; value="e;<?php if ($data_var) { echo $data_var;} ?>"e;>un'altra cosa
Now just to make sure, if the user then changes the preloaded input to something else, will the new value take over the $name variable?
For example, I may have this:
INPUT text NAME="var" VALUE="<?php if ($data_var) { echo $data_var;} ?>">
then the user changes the text in the form to "new_var". Will the stored variable be $new_var or will it be $data_var?
For example, I may have this:
INPUT text NAME="var" VALUE="<?php if ($data_var) { echo $data_var;} ?>">
then the user changes the text in the form to "new_var". Will the stored variable be $new_var or will it be $data_var?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia