The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Amateur trying to use javascript
I am a volunteer for a non-profit that does work at a state park. I have built a set of forms and views so that volunteers can enter their time. They receive rewards and I am trying to automate that process with java script.
After a volunteer donates 60 hours, in a fiscal year, they get an Annual Park Pass. I have a field that tracks fiscal hours and another field that shows the park pass status. I manually change these now.
I have attached a screen shot showing the screen and a copy of the java script I am trying to use.
Attachments:
FOCCSP-java-script-code.docx
January 7, 2019 at 5:41 am
Rather than sharing JavaScript/jQuery code in a Word document, please create a pastebin of your code and share the pastebin link here. https://pastebin.com/
As an FYI, I'm very cautious when it comes to file attachments and don't open Word documents from people I don't know, even if posted on sites I frequent regularly. Pastebin is a better way to share code.
January 7, 2019 at 7:00 am
I pasted it https://pastebin.com/JY5KVHgt
Thanks I didn't know about pastebin previously
January 7, 2019 at 7:41 am
The way this script is written, it won't do anything until you physically change the status field which also seems to be the field you are trying to automatically update. I've refactored the code to update the status field when the fiscal year hours change.
Your code also has a problem that in some places you are using curly quotes instead of straight quotes. Curly quotes won't work in jQuery/JavaScript. This could be because you are cutting and pasting from Word.
Here is your new code: https://pastebin.com/8paxLSYv
Obviously, I couldn't test this because it's specific to your form, but it should work.
January 8, 2019 at 7:20 pm
Thanks Mr. Font I have the select / case statements working.
I would now like to have an if statement test if the Status is already "Earned" or "Awarded" and if so, end the script.
I have tried and can't seem to get it to work.
jQuery(document).ready(function($){
$('#field_os5zd, #field_8hmzx, #field_xdwot').change(function(){
var val1 = $("#field_os5zd").val(); // hours field os5zd
var val2 = $("#field_os5zd").val(); // status field 8hmzx
var val3 = $("#field_xdwot").val(); //date field xdwot
val1 = parseInt(val1, 10);
console.log('aaa', val1);
switch (true) {
case val1 >50 && val1 60: val2 = "Earned";
break;
default: val2 = "Not Yet";
}
$("#field_8hmzx").val(val2);
$("#field_8hmzx").change();
});
});
Discussion closed.