Buy Now
Sign in

Setting another element onchange

hcharris , August 08 at 01:41
Answered
H
hcharris
This should be a simple problem but I'm not finding the answer on my own. I'm running chronoforms5 on Joomla 3.8.11 . I have a simple form that is getting two fields from the _users database and displaying them on the form correctly. I also have two other fields on the form: a drop-down where one selects a 1, 2, or 3 and a total field. What I want to happen is if a 1 is selected the total field value is changed to 25.00, if a 2 is selected the total field value is changed to 50.00, and if a 3 is selected the total field value is changed to 75.00. The total field is not shown (parent hidden) until the numeric field is selected.
I think I should be able to set the value in the event tab of the total field but so far I have not had any success.
Any assistance would be appreciated.
Screenshot_from_2018-08-07_20-35-17.png
H
hcharris
Update:
I did not understand and have taken a different route.
1. Added a Load Javascript in Setup: function settotal() {this.form.elements["total"].value = '25.00'; }
2. In Designer, I have added the following in Events tab:
capture.png
3. A test of the form, gives me the following html:
<script type="text/javascript">function settotal() {this.form.elements["total"].value = '25.00';
}</script>
and
function chronoforms_fields_events(){$("[name='dropdown9']").on("change", function(){if($("[name='dropdown9']").val() == "1"){if($("#fin-total, #total").closest(".gcore-subinput-container").length > 0){        $("#fin-total, #total").closest(".gcore-subinput-container").css("display", "");      }else if($("#fin-total, #total").closest(".gcore-form-row").length > 0){        $("#fin-total, #total").closest(".gcore-form-row").css("display", "");      }}});          $(':input[name="dropdown9"]').on('change', function(){            settotal()($(this));          });}
I think this is progress but the field value is not being updated when the field in the dropdown changes.
Again, I appreciate any help.
Attachments
capture.png
capture.png
(9.73 KiB)
29 Downloads/Views
capture.png
capture.png
(9.73 KiB)
42 Downloads/Views
H
hcharris
After several hours of trying , I was able to get this working.