Interaction between 2 fields

Repitol 22 Feb, 2013
Hi again !
In my form, user can register to different activities.
on the first field, he writes names to be registered
on the second field he writes number of people registered. That field calculates automatically the price to be paid in Javascript code (thanks BOB).
example :
first field (id 'noms-des-inscrits') : John DOE + Steve AUSTIN
second field (id 'nombre-inscrits') : 2

How should I avoid users that write one or several names but put 0 on the second field ?
Because of that, price to be paid is wrong, of course.
The only way to have 0 in 'nombre-inscrits' is to have 0 in 'noms-des-inscrits'

Help would be very usefull.
Thanks
Repitol 27 Feb, 2013
Hi,
nobody can give me a JS code that writes value 0 on field "number" when field "name" is 0 ?
Thanks for any help.
FloB 28 Feb, 2013
Hello!
I think, but it's my opinion, that you have a strange way for register.
I would have ask the number of person first, and then, depending of the number, show as many as number fields to ask name.
You need a field for asking the number of persons (maybe with a condition to be sure it's an integer in the field and if you want to set a limit, or maybe a dropdown). Then with some javascript, on change event and a conditional action, you could show the fields for asking the name (maybe use a defined number of fields hidden first, then unhide the 'number' first fields).

If you prefer your solution, you could count the number of '+' in the field 'noms-des-inscrits', then compare it with the field 'nombre-inscrits' (number of '+' +1 = 'nombre-inscrits') with a validation on the submit event and show an error message if the result is false.

Flo
Repitol 28 Feb, 2013
Hi Flo,
You're absolutely right !
I composed the form following strictly what was asked by the customer (ie: field names, then field number).
I didn't think users would make so many mistakes. I should have expected it...
Your solution is the best because it has many advantages :
First, user writes the number of persons for one activity (the javascript uses that field to calculate the cost at the very end of the form)
Second, that field can interact with the field 'names' and show the conditional number of lines (or fields) to writes names and birthdates (if needed)
That looks very interesting but I don't have any knowledges in javascript to perform it 😶

With the actual form, I was obliged to create a box text field, to enable users to write the names and birthdate with a tooltip like "one name + birthdate by line"

your solution would help to show the good number of lines depending on the number written on the first field 'number'
Can you help me to make it possible ?
Best regards
Repitol
GreyHead 28 Feb, 2013
Hi Repitol,

Please see this FAQ which may help you here.

Bob
Repitol 29 Mar, 2013
Hi,
Thanks for the help. I was on another project these last days and couldn't try your fix.
I will as soon as possible.
Thanks again for this forum and for quick helps we can find !
Best regards
This topic is locked and no more replies can be posted.