How to use Javascript to populate a text field based on a selection in a drop-down list?

Greetings,

I have virtually no experience with JavaScript and I'm trying to find a way to add some functionality to basic Automation to a form of Adobe.  I have a drop down box called "Hospital_Name" which will contain about 7 possible selections.  When the user makes a selection, I would like to have the field of text (called "Hospital_Address") under the drop-down list fill with the corresponding address to the selection.  I have the "Hospital_Address" text field set up for multiple lines and want the address to have a line break between the address and the city/province/postal code.

For example, if the user has selected "Hospital 1", the text field would display:

123 main St

Anytown, CA 12345

Help or you can provide examples would be greatly appreciated.

'Re missing you the document level script that sets the data object and setItems function.

document level JavaScript; Could be placed in the action open to the page if you cannot access the document JavaScripts level;

Place all the pre-population data into a single data structure
var Location = {}
' - Hospital - ': {line1: "', line2:" "" "},
'Bellevue Medical Center': {line1: "2500 BMC Drive", line2: "Bellevue, NOT 68123"},

"CHI Bergan Mercy": {line1: "7500 mercy Road", line2: "Omaha, NOT 68124"},
'CHI Emmanuel': {line1: "6901 N 72nd Street", line2: "Omaha, NOT 68122"},
'CHI Lakeside': {line1: "16901 Lakeside Hills Court", line2: "Omaha, NOT 68130"},

'CHI Midlands': {line1: "11111 s. 84th Street", line2: "Papillion, DON'T 68046"},
'Creighton University Medical Center': {line1: ' 601 n. 30th Street ', line2: "Omaha, NO 68131"},
'Nebraska Medical Center': {line1: "4400 Emile Drive", line2: "Omaha, NOT 68105"}
};

function SetFieldValues (Hospital_Name) {}
location [Hospital_Name] .line1 = this.getField("AddLine1").value;
this.getField("AddLine2").value = location [Hospital_Name] .line2;
}

end document level scripts;

custom script hits;

If {(event.willCommit)

If (event.value == "") this.resetForm (["AddLine1", "AddLine2"]); of other SetFieldValues (event.value);

}

end of custom keystroke script;

Note the formatting of the elements in a column as a line we can help revise the code. Also use a text editor for processing code.

Tags: Acrobat

Similar Questions

  • Change the border color of text field based on a value from the drop-down list

    I have a dropdown menu with 4 choices of priority for maintenance.  With a javascript script, I need to be able to select a 'priority' in a list box and a text box border then color with an appropriate color.

    'High priority' with an export value of 0

    "Medium priority" with a value of exports of 1

    'Low priority' of an export value of 2

    "When the time allowed" with a value of exports of 3

    When one of these selections has been filed, a text box becomes available in order to write the gap. My goal is as follows.

    When "High priority" is selected, the border of the text box where you write the gap would blush.

    When "Moderately urgent" is checked, the border around the text box where you write the gap would turn yellow.

    When "Low Priority" is checked, the border of the text box where you write the gap would become green.

    When "when she allows" is checked, the border around the text box where you write the gap would have turned blue.

    Otherwise, the border would be white.

    This form will be used ultimately on an iPad using Expert PDF under the player.     I use Acrobat X to create the form.

    Any help would be appreciated.

    Yes, I accidentally left a hug. I can fix it so it won't be a problem if someone tries to use it. Happy that you guessed it work.

    To handle resetting, you can use a script to validate drop-down list:

    Script to Validate drop-down list

    If (event.value = "" "") {}

    getField("discrepancy_1").strokeColor = color.white;

    }

  • Help! Script to populate a field of text based on whats selected in a drop-down list to a page?

    Well I hope I can explain this well enough.

    I have a drop down list that has two different options to choose from.  For example:

    Dropdown1 has: Option has

    Option B

    On the other page, I have two text fields.  TextField1 shows just what is levied on the Dropdown1 (Option A or Option B).  TextField2 must do the following: If Option A is taken I just need the field to remain a Virgin.  If Option B is taken out I need to fill a specific text.

    I thought that I found a way to do it, but it seems that since it's on another page the script will not pull.

    Any help is very appreciated!

    Hello

    You can download Acrobat.com and then publish the form. Once you have published, you can copy the link and share it here.

    In my example, I used the name of the first object "TextField1" for example. If your first object is named differently, you will have to modify the script accordingly.

    There is an example on how to reference objects here: http://assure.ly/kUP02y.

    Niall

  • Drop-down lists of the fill of the text fields on a different page from the drop-down list.

    Hi all

    I have a form with multiple pages. The first page contains a number of drop-down lists. These lists, drop-down list when the option is chosen, must complete a field text on another page. I can get the drop down menu to populate the text field when it is on the same page, but as soon as I move the text field to another page, the script does not work. Can anyone offer a solution? I used javascript on the changes to the scripts.

    Every time reference you the other object... so I guess in the code located on the DDlist.

    Paul

  • Automatically populate a drop-down list by using another selection from the drop-down list box

    New java/preparation forms so I apologize in advance.

    I currently have a menu drop-down box 1 (Occupation) with three options: "enter your own description/blank", retired housewife. When someone chooses either retirement or anyone at home, I would another drop box 2 (employer) to assign automatically "n/a. . The employer drop box has only two options: "enter your own/blank", N/A.

    Far, I could for that box to fill but only when the person clicks in the box (as if they were about to enter their own text.) Then only it will fill the drop-down list "employer." I would like it auto fill once the person has chosen retired, Virgin or stay-at-home woman without having to enter in the box (just using the arrow to the size of the drop-down list box).

    I currently have a key shot that resets the employer box when a person chooses the option vacuum/enter your own option. I then a JavaScript (only for the housewife now) that only works if you click the box of. Key combination works I want to than the other options work as well. If the client settles on white, the choice of the employer updates automatically empty without having to click in the box of. Any help (including general advice to make my code cleaner) is very appreciated!

    Current script of typing:

    If {(event.willCommit)

    If (event.value == "") this.resetForm (["use"]); of other SetFieldValues (event.value);

    }

    The current upward, mice running JavaScript :

    var v = this.getField ("Occupation") .value

    If (v is "Housewife")

    1. this.getField("Employer").value = "N/a".

    I think maybe I should use event.willCommit in my formula, but I'm not sure how to include it.

    Thank you!

    I would not use the key sequence or MouseUp actions for this, but the action post.

    Just make sure that you set the field option to validate the selected value immediately (under Properties - Options) and then use this code as the custom validation script:

    var employerField = this.getField("Employer");
    if (event.value=="Homemaker" || event.value=="Retired")
        employerField.value = "N/A";
    else employerField.value = employerField.defaultValue;
    
  • Select from the drop-down list and populate a list in another menu drop down

    I have a drop down list with 10 items in the list. If possible, would like for a selection in the drop-down list to populate a drop-down list with another list of selections. Each of the 10 points in the first list each will have a list of different options in the second drop-down list. I don't know how to build this solution.

    Thank you

    MDawn

    Hello

    It was because of the clear rawValue script that I put in the output from the drop-down list event businessFunction.

    I fixed it:

    // clear the current selection in the department dropdown
    dept0.rawValue = null;
    dept0.execEvent("exit");
    

    https://Acrobat.com/#d=MrWYQbTZIR7xJQDlm5ZSLg

    Good luck

    Niall

  • Populate a drop-down list based on selected in a drop-down list in a separate table

    Good day all.

    This may seem a simple question for most, but... He had me frustrated trying to figure out.

    I'm trying to fill in a drop-down list that is based on what is selected in another drop-down list.

    Let me explain what I've done so far.

    Life cycle of Designer 8.05.2

    When I got the two drop-down lists in the same table, I've not had a problem. The code I used is

    The table name is "table1".

    if (directorate.rawValue == '1')

    {

    division.clearItems ();

    division.addItem ("select" "")

    }

    I was asked to move things and now 'division' is located in 'Table2 '.

    I know that I need the "Table1" reference, but I'm running into a syntax error. I tried the following code;

    if (Table1 Row1 directorate.rawValue == '1')

    {

    division.clearItems ();

    division.addItem ("make a choice")

    }

    if (Table1.Row1.directorate.rawValue == '1')

    {

    division.clearItems ();

    division.addItem ("make a choice")

    }

    Any help would be appreciated

    Chomp

    You are missing a semicolon at the end of the line, addItem, and the second code example, you have no periods in the SOM (Table1 Row1 direction) reference.

    The best way to get the path to another field is to ctrl-click on the ground while you are in the script editor.

  • Make a field of text/hide according to the results of a drop-down list box

    Hello

    I wonder if someone could help me with this. I want to show/hide some text boxes in my form according to the choice made by the person filling in. For example, there is a dropdown list containing a selection of numbers 1-4. If 1 was selected, the text boxes below 1 would be visible and obligatory, if the 2 have been chosen, 2 text boxes below would be visible and required etc...

    I'm new to FormCalc (only started using it this morning), so simple a possible explanation would be fantastic.

    Thanks for reading!

    Of course, you can have javascript and formcalc in the form. Not only the two in the same field, same event; D

    Okey, let's try some things:

    (1) check if the "binding" from the drop-down list is the same as the values that you choose. In the script you are referring to the bound values.

    (2) other names for the Textfields would be better, because it is more difficult to refer to "Textfield1 [1]" then to for example: 'New '. I was just to lazy to give them names. (If it's on another page or subform, you refer to the fields correctly: as MyForm.FirstSubform.FirstTextfield... this name lies in the specific script field.)

    (3) check your script once more... want to make invisible mandatory fields?

    (4) check if your form is dynamic. (If it isn't you will not see the changes...)

    You should probably do it in small steps, such as:

    (1) first of all, you refer to areas such as:

    This.rawValue = Firstfield.rawValue;

    If the changed value fields got you its name and to be sure that the event you put is the right one.

    (2) try the different parts of the script and look at how it works. Problems can be more easily found and then

  • Select from the drop-down list point based on text box is not empty not

    Hello. I have a javascript code to click a button and it will insert the date in a text box named "Controller_PDF_Creation_Doc_Control_Date" in my form. I also have a drop-down list called 'Release_Approval_Initials '. Everything I'm doing is when there is a date of entry in the text box, I want that the 'Release_Approval_Initials' of the menu drop-down default by selecting the option "TM". The drop-down list is filled dynamically too. How can I do this? Here is the code I have.

    < SCRIPT LANGUAGE = "JavaScript" >

    verify() {} function

    var partNumber = ";

    var ecoNumber = ";

    var pdfDate;

    var queue;

    var queueValue = ";

    var allArray = document.getElementById('listofids').value.split (",");

    var error = false;

    for (var i = 0; i < allArray.length; i ++) {}

    pdfDate = document.getElementById('Controller_PDF_Creation_Doc_Control_Date'+allArray[i]).value;

    <!-document.getElementById ('Controller_PDF_Creation_Doc_Control_Date1') .value =' 19 / 08/11 '; ->

    queue = document.getElementById ('Release_Approval_Initials' + allArray [i]);

    queueValue = tail [queue.selectedIndex] .value;

    If ((pdfDate! = '' & & queueValue == '') |) (pdfDate == '' & & queueValue! = '')) {

    error = true;

    ecoNumber = document.getElementById('ECID'+allArray[i]).value;

    partNumber = document.getElementById('Part_Number'+allArray[i]).value;

    Alert ("You must enter a date of authorization to create PDF or Doc Control files and the queue to release for ECO" + ecoNumber + "part number:" + partNumber);

    }

    }

    {if (Error)}

    Returns false;

    }

    else {}

    Returns true;

    }

    }

    < /script >

    "< cfinput type ="Text"name =" "Controller_PDF_Creation_Doc_Control_Date #ItemID #" id = "Controller_PDF_Creation_Doc_Control_Date #ItemID #" value = "#DateFormat(Controller_PDF_Creation_Doc_Control_Date,"M/D/YY")" # "size ="12"maxlength ="8"validate ="date"required ="no"message ="you must enter a valid date in the format m/d/YY in the creation of PDF files or Doc control Date">"

    < cfinput type = "hidden" name = "today_date" id = "today_date" value = "#DateFormat (now ()," D/M/YY")" # "/ >"

    < input type = "button" value = "today's Date" onclick = "document.getElementById('Controller_PDF_Creation_Doc_Control_Date#ItemID#').valu e = document.getElementById ('today_date') .value" >

    < select name = "" Release_Approval_Initials #ItemID # "id =" Release_Approval_Initials #ItemID #">"

    < option value = "" > < / option >

    < cfloop query = "ShowDataEntryInitials" >

    < option value = "" #Initials # ""

    < cfif initial EQ ReleaseInitials > selected

    < / cfif > > #Initials # < / option >

    < / cfloop >

    < / select >

    Any help would be greatly appreciated. Thank you.

    Andy

    I figured out how to make it work. I just had to add parentheses in the right places to make it work. Here's what I did:

  • Selection in the drop-down list box determines the text to display in another box - ideas?

    Hello, my name is Zac.  I spent a lot of time trying to figure this one out for myself, but I couldn't find what I needed.  A few threads looked promising, but I realized that they only apply to the LiveCycle.  Many other threads link to discussion 2006 Thom Parker on this subject, but it is very advanced and I feel that what I need is not as complex as the solution he proposes.  I've never used Adobe Acrobat until a few weeks ago, but with the help of Bernd Alheit and George Johnson I managed to create a document with fly-out help windows and scrolling lists and radio buttons which dictate the choice.  It's great and it works.  The last thing I have to do is to create a text box (or some kind of box) which will display a pre-written block of text based on the user choice in another area (a drop-down list box).  Like this:

    image for forums 2.PNG

    I wish, it is also easy to create because it draw a picture of him!  If the user selects "Algebra 1", for example, a specific description display below.  There are a lot of courses and descriptions, and the descriptions are long enough (as shown).  It is not necessary for the user to make changes to the description - in fact, which would be terrible.  But I would like to be able to copy text from it and paste the text in another area of text on the same page.

    Thank you very much, all those who have ideas please share them! Again wild guesses. I learn from all this.

    -Zac

    This involves using a script. If you want to write the code yourself read this tutorial:

    https://acrobatusers.com/tutorials/change_another_field

    If you don't feel like messing around with the code, you can use this tool that I developed to easily set up with the help of an input file:

    Scripts custom Adobe: Acrobat - fill the drop-down list

  • Do I need to use javascript to get a text field in a PDF Tue Fill form with / date of the current day?

    I have a form for booking appointments, and here the date field to fill automatically with

    today's date and print it. I put in the format of the text field 'Date' and when I place the cursor in the

    today's date date field, poster. It disappears as soon as I tab to the next field.

    This action does need a javascript script to fill and print today's date? If Yes, where can I find that?

    Or y at - it another way to fit the text field (not counting as the current date by typing) to get the current date?

    Thank you.

    Ali

    using iMac 2.93 GHz Intel Core 2 Duo 8 GB | OS Snow Leopard 10.6.8 | Acrobat 8 Pro

    See example Acrobat JavaScript by Chris Dahl. The script can be an action script open document level or page to insert the date when the PDF file is open or use as a print action to fill the date just before printing the form. And the formatting of the field is 'None' because JavaScript applies the formatting.

  • How to make a selection in a drop-down list to open a specific pdf document?

    I have a form with several falling to the low fields. I would like to have every support on the selection of a specific existing pdf document, based on the selected item. Any help would be appreciated!

    Thank you

    Corky

    As the custom field validation script, you can use something like this (of course, adjust the values and the paths of files to match those you want, but retain the syntax of path - as I've used):

    if (event.value=="Option 1") this.openDoc("/c/files/option1.pdf");
    else if (event.value=="Option 2") this.openDoc("/c/files/option2.pdf");
    else if (event.value=="Option 3") this.openDoc("/d/temp/option3.pdf");
    // etc.
    

    Make sure that check the option to validate the selected value immediately (under properties of the field - Options) to be run as soon as a selection is made.

  • UI - how to make columns in the selection on a Drop Down list?

    I change a code from Peter Kahrel "start Script UI. I'm trying to make a searchable dropdown list has 4 columns. Research so far and I have positions in research, but I can't seem to make the columns for actual data. I think I need to change the type_ahead as the table is looking at these data. I'm stuck in the water. Can someone tell me what I need to do to get the list is displayed as a column? How can I activate the chosen = type_ahead given in four columns? Code and screenshot below:

    Window Capture.jpg

    picked = type_ahead (["bat", "bear", "beaver", "bee", "cat", "cats_and_dogs",
    "dog", "maggot", "moose", "moth", "mouse"]);
    
    function type_ahead (array)
    {
    var w = new Window ("dialog", "Quick select");
    var entry = w.add ("edittext", [0, 0, 800, 22]);
    entry.active = true;
    
    var list = w.add ("listbox",  [0, 0,800, 500], "",
    {numberOfColumns: 4, showHeaders: true,
    columnTitles: ["Non-Approved Word", "Approved Alternative", "Approved Use", "Non-Approved Use"], columnWidths: [200,200,200,200]});
    
    list.selection = 0;
    
    entry.onChanging = function ()
    {
    var temp = this.text;
    list.removeAll ();
    for (var i = 0; i < array.length; i++)
    if (array[i].toLowerCase().indexOf (temp) == 0)
    list.add ("item", array[i]);
    if (list.items.length > 0)
    list.selection = 0;
    }
    entry.onChange = function () {w.close (1)}
    if (w.show () != 2)
    return list.selection.text;
    else
    
    w.close ();
    }
    

    Yes, you can do as a palette, but you will have to change two things.

    1. target engine. At the beginning of the script, add the following:

    #targetengine "session."

    2. you may not use this code:

    If (w.show ()! = 2)
    Return list.selection.text;
    on the other
    w.Close ();

    Just use w.show (). You then add a control that, when clicked, determine what you want to do. For example, add a "Stop" button and a Manager in this sense:

    stopButton.onClick = function)

    {

    to do this

    Update

    w.Close ();

    }

    Peter

  • How can I add multi line selection in a drop-down list

    I just started with Acrobat DC. Everything is simple, until it isn't. I try to add items to my drop-down list. It's easy. I'm trying to make the choice of multi line. It is an inspection report and the choice will not fit on a single line. So after making the choice, can not read the answer. Thank you-Tim

    It is possible to do it, but only with a script and it's a kind of buggy. In other words, not really a good idea.

  • How to make a pdf that can send a form to e-mail selected in a drop-down list box?

    I'm trying to be able to create a user of a pdf file I created, select an e-mail from a drop-down list box and then hit send and have it send to this email address that has been selected.

    Thanks for the help!

    Hello

    I don't think (maybe wrong) you can do this in InDesign. At the very least, you could draw the shape in InDesign, but I guess that the interactivity between the selection of the list and the action of mail should be done with Scripting Acrobat or LiveCycle Designer if you have.

    FWIW,

    Loïc

Maybe you are looking for