I'm developing a form for SharePoint that enables a task manager to assign/unassign groups by clicking a button. Two fields: 1. Assigned Date and 2. Status
The idea is if the date field is null, clicking the button would enter Today's date and change the status to assigned. If the date field is not null, then onclick would clear the date and change the status to "na". There are over 10 groups, each with their own button.
Problem: I can't seem to get the first "if" statement to work, it appears to ignore it.
Given this is for SharePoint, doing a quick research it appears it's easiest to reference a field by the type and title. Example: $("input[title='date']").val
<button onclick="bASY">Assign</button>
<script>
var today = new Date();
var todayDay = today.getDate();
var todayMon = today.getMonth() + 1;
var todayYear = today.getFullYear();
today=todayMon + "/" + todayDay + "/" + todayYear;
function bASY() {
if ($("input[title='date.assigned.ASY']").val('')) {
$("input[title='date.assigned.ASY']").val(today);
$("select[title='po.status.ASY']").val('Assigned');
} else {
$("input[title='date.assigned.ASY']").val('');
$("select[title='po.status.ASY']").val('na');
}
}
</script>
Onclick it will populate the two fields, however even if the 'date.assigned' was not null it populates. Also, once the 'date.assigned' is not null, it doesn't go to the "else".
Aucun commentaire:
Enregistrer un commentaire