Page 1 of 1

Preloading table cells

Posted: Fri Jul 01, 2005 2:10 pm
by bwv2
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.

Posted: Sat Jul 02, 2005 8:39 pm
by Sphen001
Hi,

I'm no HTML wizard, but won't it work if you just put the number inside the value section of the input tags?

Sphen001

Posted: Sat Jul 02, 2005 9:24 pm
by neophyte
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=&quote;text&quote; name=&quote;telephone&quote; value=&quote;<?php if ($data_var) { echo $data_var;} ?>&quote;>

thanks

Posted: Sun Jul 03, 2005 9:37 am
by bwv2
That makes sense. I didn't know if assigning a value would change the variable and overwrite the user input or not. I'll try the method you suggested. Thanks for your time.

un'altra cosa

Posted: Sun Jul 03, 2005 10:18 am
by bwv2
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?

Posted: Sun Jul 03, 2005 11:31 am
by Chris Corbyn
The only way that a variable is going to be overwritten so to speak is if you assign a new value to the exact same variable.

You know, it wouldn't take long for you to test yourself ;)