after user inputs number.
hi
i want to make three input boxes, for a game, i want the player to input
three separate values which must all add up to a 100. i don't know what to use
im currently using php, but i don't know if i should incorperate some javascript
to this situation. using either select or text boxes.
this is the code of the html
<td> <input type="text" name="agg5" size ="2"> </td>
<td> <input type="text" name="pat5" size ="2"> </td>
<td> <input type="text" name="tri5" size ="2"> </td>
i want the person to enter the first number, then i make sure it is below a hundered and above 0
while also restricting their second input to below 100 - first_input and above 0
then the third to below 100-first_input+second input
thank you
how do i restricted the input in other boxes imediately...
Moderator: General Moderators
- shiznatix
- DevNet Master
- Posts: 2745
- Joined: Tue Dec 28, 2004 5:57 pm
- Location: Tallinn, Estonia
- Contact:
definatly going to be using javascript unless you want the user to click submit like a hundred times.
what i would do is have a counter at the top of the forum starting with 100. have the default value be 0 for each field then use onBlur to calculate the difference of 100 and the 3 boxes, then put that number in the counter. if they go below 0 then give a ALERT error. should not be too difficult. then you can use php to do the last bit of error checking incase they where trying to sneak a quick one past ya.
understand?
what i would do is have a counter at the top of the forum starting with 100. have the default value be 0 for each field then use onBlur to calculate the difference of 100 and the 3 boxes, then put that number in the counter. if they go below 0 then give a ALERT error. should not be too difficult. then you can use php to do the last bit of error checking incase they where trying to sneak a quick one past ya.
understand?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
If you want to actively do that restriction you must do it with Javascript. However, you'll still have to verify the result on the form processing side...
The Javascript would likely use the onchange event to run some basic code that summed the values of each of the fields to determine if the current on is out of range or not...
The Javascript would likely use the onchange event to run some basic code that summed the values of each of the fields to determine if the current on is out of range or not...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
in your case, you'd use the Javascript function parseInt() on each of the "other" values, so if you were in field two, you'd parseInt() the first and third fields' value properties. Afterwhich, you add them together and subtract that from 100.. the result is the allowed range of that field. Simply parseInt() that field's value property and compare...