Jump to content
  • 0

Value of a -custom values- dropdown change


theconav
 Share

Question

Hello !

I ve been struggling with this for quite sometime now without any result :(

I have a details page containing the following fields among others :

Current_Status = Dropdown list with custom values (New,Assigned,Scheduled,Performed)

Assigned_AE = Cascated Dropdown

Close_Date = Date field

A Today Variable should also be configured to reflect todays date.

I would like upon submission of the form to change the value (to one of the 4 standard values contained on the dropdown list) of Current_Status, based on the following criteria :

IF Assigned_AE.value = "-None-"

Current_Status.Value = "New"

ELSE

IF Close_Date IsBlank

Current_Status.Value = "Assigned"

ELSE

IF Close_Date > Today

Current_Status.Value = "Scheduled"

ELSE

Current_Status.Value = "Performed"

ENDIF

ENDIF

ENDIF

Could someone pls help me with the JS code ? I have tried a lot of different things without any luck !

Thank you very much in advance.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi theconav,

Please try the following code. Remember to substitute field names and ids with the ones you used when creating your form.

Let me know if this helps!

<script>
var setCurrentStatus = function(status) {
    document.getElementsByName('EditRecordCurrent_Status')[0].value = status;
}

document.getElementById('caspioform').onsubmit = function() {
    var assignedAE = document.getElementsByName('EditRecordAssigned_AE')[0].value;
    
    var closeDate = document.getElementById('EditRecordClose_Date').value;
    
    var today = new Date();
    today.setHours(0,0,0,0);
    
    if(assignedAE == '-None-') {
        setCurrentStatus('New');
    } else if(closeDate == '') {
        setCurrentStatus('Assigned');
    } else {
        closeDate = new Date(closeDate);
        closeDate.setHours(0,0,0,0);
        
        if(closeDate > today) {
            setCurrentStatus('Scheduled');
        } else {
            setCurrentStatus('Performed');
        }
    }
}
</script>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...