Preloading table cells

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Preloading table cells

Post 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.
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post 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
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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;>
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

thanks

Post 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.
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

un'altra cosa

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
Post Reply