Skip to main content
Known Participant
May 3, 2024
Answered

Dropdown box fill with dashes in blank space after entering value.

  • May 3, 2024
  • 1 reply
  • 1575 views

I have a dropdown list in acrobat form. I want to achive this that after selection of item from dropdown list it will calculate the blank space available in the dropdown box and fill it with "------------------". 

 

The number of "dashes" required to fill the box will change depending on the item selection from the dropdown list. Thanks in advance. Please Help!!!

This topic has been closed for replies.
Correct answer try67

Yes. Default value is blank.


Use this code:

 

if (event.value!=event.target.defaultValue) {
	var selectedText = event.value;
	var remainingSpace = 30 - selectedText.length;
	var dashes = "-".repeat(remainingSpace);
	var filledText = selectedText + dashes;
	event.value = filledText;
}

1 reply

try67
Community Expert
Community Expert
May 3, 2024

Why do you need to calculate it? The values of the drop-down box are fixed, aren't they? Just count how many dashes fit for each value and then hard-code it in your script. Calculating the length of a random string in a (non-monospaced) font is extremely difficult.

elendil84Author
Known Participant
May 3, 2024

I apolozize for my shortcommings. I am unable to code it in the way you are instructing.

try67
Community Expert
Community Expert
May 3, 2024

All you need to do is the following:

if (event.value=="Option 1") event.value = "Option 1---------";

else if (event.value=="Option 2") event.value = "Option 2-----------";

else if (event.value=="Option 3") event.value = "Option 3---------------";

etc.

And use it as the field's custom Format script.