PDA

View Full Version : Form Question


FaaipDeOaid
12-29-2003, 05:56 PM
Hey, I'm making a form on a website that I require button help with...

I have several fields that numbers are entered in [8 fields to be exact] and I want to add a button that will insert numbers into those fields for people who are too lazy to fill the fields themselves.

This is for a nonprofit online roleplaying game, I'll give you an example of what I mean.

( |___| = the next field box ; [button] is the button)

Vitality |__|
Strength |__|
Endurance |__|
Resistance |__|
Mind |__|
Willpower |__|
Speed |__|
Dexterity |__|

[Brute] [Mind] [Stealth] [Willful] [Well-Rounded]

When Brute is clicked, I want the eight number fields to be filled with average Brute numbers, and when Mind is clicked they are filled with average Mind-user numbers... et cetera. Any help would be appreciated.

bassrek
12-30-2003, 10:18 AM
Here's a snippet that should get you started:

<script langugage="JavaScript">
<!--
function AutoFill(theVals) {
var theFields = theVals.split(",");
for (var i = 0; i <= 1; i++) {
document.RP[i].value = theFields[i];
}
}
-->
</script>

<!-- indside of the body of your HTML page...-->

<form name="RP" action="page.htm">
Vitality : <input type="text" name="vitality" size="5"><br>
Strength : <input type="text" name="strength" size="5"><br>
<input type="button" name="af_Brute" onClick="AutoFill('1,2')" value="Brute"> |
<input type="button" name="af_Mind" onClick="AutoFill('2,4')" value="Mind">
</form>

Inside of each button in an onClick event, with a list of default values. Just put the default values inside of the single quotes in order for each attribute. Inside of the AtuoFill function, there are two thigns to pay attention to. I have the for loop only running twice since I only setup 2 attributes. When it's all done, you'll have to change it to read

for (var i = 0; i <= 7; i++) {

to get all 8 attributes. Also, I'm assuming you don't have any form elements before these text boxes. If you have, you'll need to make adjustments. For example, if you have 4 text boxes before these in the same form, you'll need to change inside the for loop to

document.RP[i+4].value = theFields[i];