Copy link to clipboard
Copied
Hi,
I have a form with a number of templates.
Each template is named with a 2 or 3 character name – e.g. "TH", "MON".
The field names on each template are named using the template name followed by a space and some text – e.g. "TH Head 1", "TH Dropdown 1", "TH SI 1", "MON Head 1", "MON Dropdown 1", "MON SI 1".
On each template I have a field comprising the template name followed by a space and "no items" - e.g. "TH no items", "MON no items"
My code below (with thanks to try67) attached to this field hides or displays the other fields.
In order to avoid rewriting the code for each template, what I want to do is to use the first 2 or 3 (depending on the field name) characters as a variable to add to the beginning of the other field names.
I thought that if I could find the position of the first space in the field name I could use this to ascertain what characters to use as a prefix.
For example, the code below is attached to the field "TH no items". Instead of me having to manually insert the value for "var d" each time, I want to dynamically ascertain the value.
How do I ascertain whether it is 2 or 3 characters I need and then select them?
Thanks
Raymond
var qq = 10 // Maximum number of items
//var b = getField(event.target.name) //Field name
//var c = find(" ",b)
var d = "TH"
var z = Number(getField(event.target.name).valueAsString);
if ( (z.length === 0) || (z <1) || (z > qq) )
{ app.alert("This field is required. Please enter a value between 1 and " + qq)
this.getField(event.target.name).setFocus()
}
if (( z>=1) && (z<=qq))
{for (var i=1; i<=qq; i++) {
this.getField(d+" Head "+i).display = (i<=z) ? display.visible : display.hidden;
this.getField(d+" Dropdown "+i).display = (i<=z) ? display.visible : display.hidden;
this.getField(d+" Dropdown "+i).readonly = (i<=z) ? false : true;
this.getField(d+" "+i).display = (i<=z) ? display.visible : display.hidden;
this.getField(d+" "+i).readonly = (i<=z) ? false : true;
this.getField(d+" SI "+i).display = (i<=z) ? display.visible : display.hidden;
this.getField(d+" SI "+i).readonly = (i<=z) ? false : true;
}
getField(d+" Dropdown 1").setFocus();}
All you want to know is here: https://www.w3schools.com/jsref/jsref_indexof.asp
For example:
var text = "This is some text";
var text2 = "NoSpaces";
console.println(text.indexOf(" ")); // returns 4
console.println(text2.indexOf(" ")); // returns -1
Copy link to clipboard
Copied
You can get the index of a character or string with the method indexOf.
Copy link to clipboard
Copied
For example:
var text = "This is some text";
var text2 = "NoSpaces";
console.println(text.indexOf(" ")); // returns 4
console.println(text2.indexOf(" ")); // returns -1
Copy link to clipboard
Copied
All you want to know is here: https://www.w3schools.com/jsref/jsref_indexof.asp