If date element is not null then change another element to 3rd Dropdown selection

Discussion in 'Standard Support' started by Bren, Dec 4, 2017.

  1. Bren

    Bren Member

    Level: Standard
    Hello all.
    I have a form with a date element that if a date is added then the user should also change the Dropdown element beside it to the 3rd drop down value. The user should do this every time; but the user forgets. So, it would be nice if during form submission or when the user selected the date that this automatically happens. My 1st thought was that maybe some JS in the date element would work or maybe during the form submission...
    Regardless, I’m not sure what JS code to use (I haven’t used either option, yet). Any suggestions?
    Thanks in advance.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    Try putting a JS event on the date element, on 'change' ...

    this.form.formElements.get('yourtable___yourdropdown').update('x');

    ... which x is the value of the dropdown option you want to select. So not '3' (for third), but the actual value of the third option.

    -- hugh
     
  3. Bren

    Bren Member

    Level: Standard
    I just tried your suggestion and it works perfectly. Thank you, Hugh.
    One more question. It would be even cooler if the user selected this particular Dropdown element item and the date element (if empty) changed to today's date. Could I trouble you for your suggested JS to put within the Dropdown element to make this happen?
    Thanks in advance.
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    Use on 'click' (maybe 'change', but I think that doesn't work for dropdowns in some browsers).

    Code (Text):

    if (this.getValue() == '3') {
       var date = new Date();
       this.form.formElements.get('yourtable___yourdate').update(date.format('%Y-%m-%d'));
    }
     
    Replace '3' with the value you want, and yourtable___yourdate with date element name.

    -- hugh
     
  5. Bren

    Bren Member

    Level: Standard
    Awesome! I just tried it and it worked great. Thanks again, Hugh.
     

Share This Page