Hello to all,
I have an insert form. I need that in the total field, change the amound depending if in another select field the person choose yes or no. For example, if the person choose “Yes” then in total shows $100 as the value to be inserted when hit the submit button or $50 if choose “No” in the select field. That is possible in wappler?
Thanks in advance
Hello to all,
Yes, it’s possible. You can set the select field values to the numbers you need and use it in a math formula in your total field. Example:
dmx-bind:value="(input1.value.toNumber() + input2.value.toNumber()) * select.value.toNumber()"
I am assuming that in the formula, where says “input1”, “input2” … is the select field name? second, where says “value” is the “Yes” or “No”? and where says “toNumber” is the number that I want? and that formula is in the Total field, I not need to do anything in the select field?. Also where in wappler I make the math?
input1 is a random name of an example form input on your page and this is just an example formula.
Maybe if you post your form code and explain the logic you want to follow it will be easier for me to explain you what you need to achieve.
So what is the logic for the total field? Also its better if you just paste the code, i can’t copy code from your screenshots
Also i see 85 syntax errors on the page, better check them as well.
I didn’t place any logic or formula in the code yet about what I want to do. This is the select field:
<select id="inp_additionalticket" class="form-select" name="additionalticket"> <option value="No">No</option> <option value="Yes">Yes</option> </select>
And this is the Total field where I want the formula. Basically if in the select field the value is “Yes” then the amount in total sould be $1,375.00 and if the value is “No” the amount should be $1,250.00.:
<label for="inp_TOTAL" class="col-sm-2 col-form-label">Total:</label> <div class="col-sm-2"> <input type="text" class="form-control" id="inp_TOTAL" name="TOTAL" aria-describedby="TOTAL_help"> </div>
About the syntax errors, yes, jejeje
So you need to do this:
<input type="text" class="form-control" id="inp_TOTAL" name="TOTAL" dmx-bind:value="inp_additionalticket.value == 'No' ? 1250 : 1375 " aria-describedby="TOTAL_help">
Excellent, Thanks a lot, it works!!!
Is possible to do it as a string? ($1,250) I tried but not show info.
dmx-bind:value="inp_additionalticket.value == 'No' ? '$1,250' : '$1,375' "
Thanks, I was placing " instead '. My last question, If I would like to add more parameters, like if say “maybe” for example and so on. how I do that in the code?
are not math what I trying to do. Basically the same thing that you did but adding more. in your code, if the client choose “No” then the amound will show as 1250 else will show 1375. I would like to add more to that, for example if there 3 parameters in the other field like “yes”, “no” and “maybe” then will show in the total fiel an amound depending the selection. In the code you send and thanks a lot for that, there to parameters to be choosen, I would like to add more.
Please help, that is possible?
Please epxlain in details with examples what exactly do you need to achieve, so i can help you. I need to see your exact use case to answer.
With the code that you sent me I solve my first problem. I have a select field with “Yes” and “No” option and if the client chooses “No” in the total field show an amount due and if choose “yes” show another amount. Now, I want to add more options in the select field. For example “Yes”, “No” and “Maybe” depending on the selections shows 3 different amounts in the total field. How can I do that? with the code that you send me, if “No” is chosen shows an amount, and else will show another amount.
dmx-bind:value="inp_additionalticket.value == 'No' ? '$1,250' : inp_additionalticket.value == 'Yes' ? '$1,375' : '$ MAYBE VALUE' "
Just to be clear, in the third option instead ‘$ MAYBE VALUE’ , should be: inp_additionalticket.value == ‘Maybe’ ? ‘$xxx’
And then and can continue adding using the same parameters?