If/Then JavaScript

Hi all,
I am working on a form that automatically fills itself out based on what the user selects using a dropdown box. I am encountering difficulties as, while I am proficient in Excel lingo, I know nothing about Java. I currently have a dropdown box where the user can select one of 4 choices. Based on that selection, I need another part of the form to fill in automatically. If anyone could assist me with this problem I would greatly appreciate it!
I would like the script to accomplish the following:
If the dropdown item selected reads "All Equity", I need the value to be 99.
If it reads "75-25", I need the value to be 75.
If it reads "50-50", I need the value to be 50.
If it reads "25-75", I need the value to be 25.
The dropdown menu is named "Portfolio Allocation" and the target/output blank is named "Equity Allocation".
Any help/tips would be great! Thanks!

Since Arobat 6.0, the Windows version of Acorbat has had 2 programs that can create forms, Acrobat and LiveCycle Designer. Both programs can use JavaScript but the exact syntax can is different for field access.
Because of your field's nane it appears you are using Acorbat's AcroForms.
// get the value of field 'Portfolio Allocation'
var sResult = this.getField('Portfolio Allocation').value;
switch(sResult) {
case 'All Equity':
event.value = 99;
break;
case '75-25':
event.value = 75;
break;
case '50-50':
event.value = 50;
break;
case '25-75':
event.value = 25;
break;
default:
// all other answers
// clear field or other action
event.value = '';
break;
// or
// clear field
event.value = '';
// get the value of field 'Portfolio Allocation'
var sResult = this.getField('Portfolio Allocation').value
if(sResult == 'All Equity')
event.valaue = 99;
if(sResult == '75-25')
event.value = 75;
if(sReslult == "50-50")
event.value = 50;
if(sResult == '25-75')
event.value = 25;

Similar Messages

  • If/then JavaScript help needed

    Hello,
    I am trying to write a script for a fillable PDF in Adobe Acrobat, but I don't have much experience with JavaScript and I need some help!
    Basically I have five fields as follows:
    A1 = a checkbox
    B1 = a field with a number value in it
    C1 = a field with a number value in it
    D1 = a field with a number value in it
    E1 = a field where the sum calculation will be.
    I want to write a script that will enter the sum of values of B1+C1+D1 into E1 if the checkbox in A1 is checked yes.
    If it is not checked yes, then it will enter the sum of values of B1+C1+ the value of D1 divided by 2 (and rounded down) into E1.
    Can anyone help??
    Thanks!

    This should do it as the custom Calculate script for E1:
    // Custom calculate script
    (function () {
        // Get the field values, number fields as numbers
        var a1 = getField("A1").value;
        var b1 = +getField("B1").value;
        var c1 = +getField("C1").value;
        var d1 = +getField("D1").value;
        // Set this field (E1) value based on the state of the check box
        if (a1 === "Off") {
            event.value = b1 + c1 + d1;
        } else {
            event.value = b1 + c1 + Math.floor(d1 / 2);

  • Hyperlink - How to execute it action function(Java) and then JavaScript

    Hi all, I have a hyperlink in a popup window. When the hyperlink is clicked I want it's action function to be executed. This works fine, the problem is when I put java code in the hyperlink's javascript onClick() function, only the onClick() gets called and not the action function.
    I need the onClick to close the window and submit the main form and I need the action function to set some session variable.
    Thanks in advance for any replies.

    Hi, thanks to anyone that read my post. I found a solution. I removed the code from the hyperlink's javascript onClick and placed it the body onload javascript function. I also set a flag to true when the hyperlink is clicked and only execute the code in the body onLoad() when the flag is true.

  • If, then, javascript calculation on pdf form

    I have a form with a grid which lists credit cards transaction amounts, with a drop down box for "type of credit" (visa, mastercard, discover).  The bottom of the form has 3 different total lines; one for each of the credit card types.  I would like to know how I get the amounts entered on the grid above to be included onto the correct total line, depending on what type of credit card was chosen from the dropdown on that row.  Since I'm not versed in java script, I'm having difficulty figuring out how to accomplish this type of calculation

    I would recommend that you post this question over in the Acrobat Forms area as the folks there can help you best.

  • How to get a pdf form to work without enabling JavaScript

    I have two users at my job that need to user a form to validate charters, the form has a text field where the user enters the charter number and it pre-propulates the form with the institutions name, address, number, etc. We are in a locked down Windows 7 enviroment controlled by Group Policy. Our security policy does not allow enabling JavaScript in our enviroment so that breaks the form. I was able to get the form to work by first enabling Javascript, then by adding the document to the trusted locations list in the enhanced security tab. But since JS is not allowed to be enabled is there another workaround for me to get these few users up and running? The fix would have to be applied via Group Policy. We are using Adobe Acrobat 9 Pro.

    You would have to use either FileMaker to create such forms and use two related databses (relational Database) Of use a Form Created in Word using a Look up list.
    Tele your company ite better to use Javascapit than the alternative of Active-X  in a Word Form or if using  a Mac Using AppleScript. of the three  AppleScript first, Then Javascript, The avoid Active-X at all cost.

  • JavaScript Error 45

    When I open InDesign CS3 I get JavaSript Error 45, Object invalid, Line 387. Then JavaScript Error 45, Object invalid, Line 345. Then when I try to open or create a new file the application crashes. What can I do?

    Some ideas:
    Retry from a new user account. That will eliminate at least user specific scripts.
    Search for any "jsx" files within "startup scripts" folders, and put them in a safe place.
    Do that only one by one, and restore them after retry if the problem continues.
    It may be a good idea to reinstall InDesign. Leaving that to others to explain.
    If nothing else helps, here is an unusual approach:
    Quit InDesign if it is still open.
    Open /Applications/Utilities/Terminal.app
    Copy paste the following line, eventually adjust the folder path within the quotes if you have a different install directory.
    sudo dtruss "/Applications/Adobe\ InDesign\ CS3/Adobe\ InDesign\ CS3.app/Contents/MacOS/Adobe\ InDesign\ CS3" 2>&1 | grep jsx
    Press the return key
    Enter your admin password when asked.
    Press the return key
    InDesign should launch. Wait a while, startup progress will be slower than usual.
    The output in the terminal window is a trace of all system calls, filtered for the "jsx" file extension of script files.
    When the error dialog pops up, do NOT dismiss it. Switch back to Terminal. Review the last few output lines there, maybe copy them here for discussion or ask in the scripting forum, whether the mentioned files belong to the default installation or not. You can safely ignore anything with "XHTML", "Xml Rules", "OEBExport" or "Digital Edtions".
    For details on dtruss, see
    http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/dtrus s.1m.html
    Good luck,
    Dirk

  • Sending Javascript call in servlet response.

    I am calling a servlet from a javascript ( .js) file. Based on the status of the server I want send javascript function call to the client browser.
    Is it possible?
    Here is what I am trying to do :
    response.sendRedirect("javascript:myfinction()");
    myfunction() is defined in the source .js file from where I am calling the servlet.
    Hope you understand what I am trying to do. Please help.
    Thanks
    Pradip

    That won't be possible as the servlet executes first on the server, then javascript executes on the client.
    Remember that Javascript requires the browser to do anything, it's the browser functionality that it runs in. The servlet executes on the server, then forwards to the client, and therefore has no access to javascript whatsoever, at least not in the context that you're speaking of. By the time javascript is ready to start, the servlet has already completed.
    If it was the other way around, that would be possible (i.e. use JSP/Servlet to set javascript variable value).
    Sorry.

  • Calling Msg-Box on condition with jQuery/Javascript

    Hello experts! I am stuck with my development as I don't know how to write the jQuery code.
    I want to call a message box (in fact an invisble DIV) when the value of my page item "P2008_MX_MODE" equals one.
    I have the following code for the message box but do not know how to add the conditional display when my page loads.
    Can you please help me on this?
    <script type="text/javascript">
    $(function()
    {$("#dialog").dialog({
                   autoOpen: false,
                            bgiframe: true,
                   modal: true,
                   buttons:
    {Schliessen: function(){$(this).dialog('close'); }}
         </script>
    <div id="dialog" title="Attention!">
    <p>
    <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 30px 0;"></span>According to the official guidelines the evaluation for this area needs to be carried out manually!</p>
    </div>I appreciate any help and effort!
    Regards,
    Seb

    Hello Jari!
    I set it with a query!
    I am currently experimenting with a process after page load that is supposed to call the message box when cnumber is <> 0. It's basically the same as my page item P2008_MX_MODE.
    Nevertheless, my procedure is not working yet. Don't know how to call the jQuery function if my condition is true!
    declare
    cnumber number;
    begin
    Select distinct count(*) into cnumber from vt_punktdaten_join where STR_LRT_MAIN in ('9133','9132','9134','9181','9182','9183','9184','9185','91E3','91E4','91E5','91E6','91E7','91E8','91E9','9411','9412','9413','9414','9415','9416','9170') and cnt_gebiet = :p2008_cnt_GEBIET
    and int_status_sub = 3 and (str_lrt_main = :p2008_str_lrt) and (INT_BE_MAIN) = :p2008_BE;
    If cnumber != 0 then
    javascript:$('#dialog').dialog('open');
    End if;
    end;If you have an idea, please let me know!
    Thanks so far!
    Seb

  • Javascript will not let me load my homepage directly.

    My homepage, "My Yahoo" told me that my password had been compromised and asked me to change my password. I checked in my account to make sure this was not a hacker out to get my password. It was legitimate so I changed my password. Since then, javascript has popped a message on my screen when I try to load the internet. It says, "Invalid username/password combination." Then it tells me to try to use my e-mail address as my username. I am supposed to be permanently checked into "My Yahoo". Instead, after getting the message, I am kicked off of the "My Yahoo" screen and put back into the general Yahoo screen. I have to sign in all over again to get back to "My Yahoo". This same type of thing happened when I changed my homepage to my Windstream account homepage. It only happens when I first load the internet. After that, I browse normally.
    Any help will be appreciated.

    1) Partition your hard drive or add an external drive and install Snow Leopard (with the Optional Rosetta) into it and then you can dual-boot (System Preferences:Startup Disk) into Snow Leopard and run FCE 3.5 there.
    2)  Use one of the following methods to install FCE 3.5 into Mavericks:
    a)  Pacifist:  http://www.charlessoft.com/
    b)  Jeremy Johnstone's Terminal method:  http://www.jeremyjohnstone.com/blog/2012-03-11-installing-final-cut-pro-studio-2 -0-on-mac-os-x-10-7-lion.html
    Reports on this forum seem to confirm that Final Cut Studio 2 will continue to operate in Mavericks once it is functionally installed, albeit some plug-ins may fail to function.  FCE 3.5 is the same generation as FCS2, and presumably will continue to operate in Mavericks, as well.

  • Hmm...Disable Javascript = fast page loads, but...

    ...it kills the "Full Text Editor" from loading. And since the link for composing a message in HTML  is wrapped in the Javascripted F.T.E., I can't access it, either.
    I just had the fleeting idea to try disabling Java, and then Javascript (and then both) in my browser (Firefox 3.0.x on Mac OS X 10.4.11) to see what would happen.
    SUMMON-A-MITCH!!! The pages load almost as fast as they used to in the WebX forums.
    Too bad it kills my ability to also participate.

    Phos±,
    Is it possible to read the web pages and participate only by posting through email?  Just thinking out loud…

  • Using Excel VBA to save PDF file as a text (plain) file?

    I'm using 8.0 Acrobat Pro.
    Third party apps are not an option (I'm restricted from installing anything on my office PC).
    I could simply save each PDF manually, but given the number of files this would not be practical.
    The text it will output does not have to be pretty by any means (and I'm aware it won't be).
    As long as I can get the PDF files in a text file format, there would be no further obstacles for me - because I would then be able to get Excel to gather-import all the data and consolidate-clean-organize everything accordingly at that point.
    What's in these PDF files are simply names, numbers, and email addresses (basic office text type data stuff simple).
    I wish to save them all as text files, and then use Excel to suck all the data from those newly created text files and consolidate-organize them accordingly.
    The VBA module I've seen referrenced around the web is the following beneath; however, I am having no luck with it.
    I keep getting the error message:
    ActiveX component can't create object or  return reference to this object (Error 429)
    I am running Microsoft Office 2010 | Excel (and using Adobe Acrobat Pro 8.0).
    Any help is extremely appreciated.
    Here is the VB code in Excel I'm having trouble with:  What this is supposed to do is simply find the specified PDF file and save it as a Plain Txt File.
    Sub Convert_PDF_To_Text_File()
    Dim AcroXApp As Object
    Dim AcroXAVDoc As Object
    Dim AcroXPDDoc As Object
    Set AcroXApp = CreateObject("AcroExch.App")
    AcroXApp.Hide
    Set AcroXAVDoc = CreateObject("AcroExch.AVDoc")
    AcroXAVDoc.Open strPDFPath, "Acrobat"
    AcroXAVDoc.BringToFront
    Set AcroXPDDoc = AcroXAVDoc.GetPDDoc
    Dim jsObj As Object
    Set jsObj = AcroXPDDoc.GetJSObject
    jsObj.SaveAs strOutputFile, "com.adobe.acrobat.plain-text"
    AcroXAVDoc.Close False
    AcroXApp.Exit
    End Sub

    one other thought is that you can create text files with a batch process inside of acrobat.  Advanced ---> Document Processing ----> Batch Processing.
    Choose new sequence, give it a name
    Step 1: Select Commands ----> Choose "execute javascript", then hit "Add."  Click on "Execute Javascript" that was just added on the right, then hit the edit button and toss in the script below that I grabbed from the javascript samples (also, if your docs have multiple pages you'll need to embed the for loop into another for loop that cycles through each page).  You'd also want to change the name of the saved txt file to the name of pdf you're doing it to.  It shouldn't be that hard, but I'm guessing you're probably alot more familiar with VBA then javascript which is why you're choosing to do it from excel.  I'm kind of in the same boat of having written a bunch of VBA, but not much javascript.  I highly recommend investing some time into learning acrobat scripting b/c VB does have it's limitations when it comes to messing with PDF's.
    * function to extract the text content of the current page and save to a file.
    try  {
    var p = this.pageNum;
    var n = this.getPageNumWords(p);
    app.alert("Number of words in the page: " + n);
    var str = "";
    for(var i=0;i<n;i++) {
    var wd = this.getPageNthWord(p, i, false);  
    if(wd != "") str = str + wd;  
    // save the string into a data object
    this.createDataObject("whatever.txt",str); 
    // pop up a file selection box to export the data
    this.exportDataObject("whatever.txt");
    // clean up
    this.removeDataObject("whatever.txt");
    } catch (e)  { 
    app.alert(e)

  • How to calculate fields in a form?

    Hello,
    I am new to apex and i have a question about create a simple calculation in a form.
    I created a form and i have 3 fields which i want to use for calculating.
    Field 1/ field 2 = field 3
    when the user enters data into the first and second field it will automatically calculate the third field.
    How can i do this?
    i am using
    Application Express 4.2.1.00.08

    The short answer is that it depends. I'm assuming you want the calculation to appear as soon as the second value is put in, and if this is the case then javascript is the answer. You can create a generic javascript function that does division and takes to input parameters and returns the result. Inside the function you would check to make sure the denominator isn't zero (an illegal operation), do the math and assign the calculated value to the return value of the function.
    The function code would look something like this:
    function div_values(numerator, denominator) {
    // pass page item names into the function
    // $v will get the value from the item name
    if ($v(denominator) != 0) {
    result = $v(numerator)/$v(denominator);
    return result;
    }Then you can call the function via a dynamic action by selecting a "Javascript Expression" for a Set Value operation (Advanced dynamic actions) and put this into the Javascript expression area:
    div_values(P1_NUMERATOR,P1_DENOMINATOR)
    The reason I recommend creating this little function as opposed to just doing the math in the javascript expression area is that the function becomes reusable and the page items aren't hard coded into the function. Then you can use the function wherever you want to on the page or, if you put it in a place where every page can get to it, you can use it anywhere in the app.
    Earl

  • Save as to Excel using vba

    Post Author: shark70
    CA Forum: Desktop Intelligence Reporting
    Hi
    The vba below saves a file into excel then does some formatting but I need to use the saveas function to set a password for the excel file when opening.
    The code in bold is where I am getting stuck
    Any ideas on where I'm gioing wrong, I'm fairly new to vba unfortunately
    Cheers
    Sub SetantaDSAT()
    ActiveDocument.RefreshActiveDocument.SaveAs ("K:\CLIENTS (LIVE)\Setanta\08. New Daily Reports\DTT and DSAT Case Type Reports\2008\May 08\") & Format(Date, "ddmmyyyy") & "_" & " TestSetanta DTT Case Type_Subtype Analysis" & ".xls"
    Set xlsApp = CreateObject("Excel.Application")xlsApp.Visible = TruexlsApp.Workbooks.Open ("K:\CLIENTS (LIVE)\Setanta\08. New Daily Reports\DTT and DSAT Case Type Reports\2008\May 08\") & Format(Date, "ddmmyyyy") & "_" & " TestSetanta DTT Case Type_Subtype Analysis" & ".xls"
    With xlsApp.Worksheets("DSAT Case Type").Activate.ActiveWindow.DisplayGridlines = False.Columns("B:B").EntireColumn.AutoFit.Columns("C:C").EntireColumn.AutoFit.ActiveWindow.Zoom = 75.ActiveWorkbook.SaveAs Filename:="C:\James\Check\Book22.xls", _        FileFormat:=xlNormal, Password:="test", WriteResPassword:="", _        ReadOnlyRecommended:=False, CreateBackup:=FalseEnd With
    End Sub

    one other thought is that you can create text files with a batch process inside of acrobat.  Advanced ---> Document Processing ----> Batch Processing.
    Choose new sequence, give it a name
    Step 1: Select Commands ----> Choose "execute javascript", then hit "Add."  Click on "Execute Javascript" that was just added on the right, then hit the edit button and toss in the script below that I grabbed from the javascript samples (also, if your docs have multiple pages you'll need to embed the for loop into another for loop that cycles through each page).  You'd also want to change the name of the saved txt file to the name of pdf you're doing it to.  It shouldn't be that hard, but I'm guessing you're probably alot more familiar with VBA then javascript which is why you're choosing to do it from excel.  I'm kind of in the same boat of having written a bunch of VBA, but not much javascript.  I highly recommend investing some time into learning acrobat scripting b/c VB does have it's limitations when it comes to messing with PDF's.
    * function to extract the text content of the current page and save to a file.
    try  {
    var p = this.pageNum;
    var n = this.getPageNumWords(p);
    app.alert("Number of words in the page: " + n);
    var str = "";
    for(var i=0;i<n;i++) {
    var wd = this.getPageNthWord(p, i, false);  
    if(wd != "") str = str + wd;  
    // save the string into a data object
    this.createDataObject("whatever.txt",str); 
    // pop up a file selection box to export the data
    this.exportDataObject("whatever.txt");
    // clean up
    this.removeDataObject("whatever.txt");
    } catch (e)  { 
    app.alert(e)

  • Need input for my requirement?

    HI all,
    I have requirement like this.
    Client  have this existing logic.
    The javascript downloads the exchange rates from the internet site abc.com by using the user name for xxxx  and stores in the .CSV file .
    Another Vb.net program takes that file and reformat it to suit SAP and saves in our file server for pick up.
    Now my client want to do it in using PI7.1
    How to do it.Please give your inputs.
    Thanks.

    You can make use of a BPM here
    JAVAScript (SOAPReq) -
    > ReceiveStep ---> TransformationStep ---> SyncSend(to Internet site via SOAP) ---> Transformation (to convert the Internet site response to the SAP format) ---> SendAsync(to File server)
    Assuming that you do not need a CSV file anymore and VB.net program needs to be replaced
    If you need a CSV file and also a SAP supported File then:
    JAVAScript (SOAPReq) -
    > ReceiveStep ---> TransformationStep ---> SyncSend(to Internet site via SOAP) ---> Transformation(Internet site response to File format) ---> SendAsync (Need to apply FCC in the receiver File CC to convert to .csv file) ---> Transformation (to convert the Internet site response to the SAP format) ---> SendAsync(to File server)
    If there is anything else that you are looking at then may be more details would be required from your side.
    Regards,
    Abhishek.

  • Popup a window in the after-submit process

    I have created a java script function in html header of the page as following:
    <script language="JavaScript" type="text/javascript">
    function myPopup (p_search) {
    var val1 = document.getElementById(p_search).value;
    var url;
    url = 'f?p=&APP_ID.:3:&APP_SESSION.::::P3_ENAME:' + val1;
    w = open(url,"winLov","Scrollbars=0,resizable=0,width=700,height=400");
    if (w.opener == null)
    w.opener = self;
    w.focus();
    </script>
    I want to call this function in one after-submit process like this:
    begin
    select name into p_name
    from vehicle
    where id = 32;
    if SQL%ROWCOUNT = 1 then
    javascript:myPopup(p_name);
    end if;
    exception
    when others then
    null;
    end;
    When I apply the changes in the application builder, I got this error:
    1 error has occurred
    ORA-06550: line 7, column 16: PLS-00103: Encountered the symbol "" when expecting one of the following: := . ( @ % ; The symbol ":=" was substituted for "" to continue.
    How do I call the java script functions in the page process? What did I do wrong?
    Any help will be greatly appreciated.
    June

    O.K. I think I got it working now. See
    http://htmldb.oracle.com/pls/otn/f?p=31517:50
    There is an on submit process multiplying the number you enter by two and populating the target item. The process is running only if there is number entered. If you enter any other string a pop-up window will show you an error message. The approach is simple:
    1. create a process which does something on submit, if the supplied parameter is O.K. and nulls if not,
    2. created a branch to an empty page which fires on submit and it is conditional - using process exception(s),
    3. on the empty page there are two onload javascript calls:
    onload="javascript:popUp2('f?p=&APP_ID.:201:&SESSION.::&DEBUG.:::', 700, 700);javascript:redirect('f?p=&APP_ID.:50:&SESSION.::&DEBUG.::');"
    the first one is opening the required pop-up page and the next one is redirecting back to where we started.
    I don't know if there are any security issues with this approach. It is not so clean, since you need to create an additional empty page. However, it saves some coding of extra scripts.
    What you are saying I also had in mind.
    Denes Kubicek

Maybe you are looking for

  • HT1386 I have itunes installed it is for my ipod question is can i sync my ipad to the same itunes and how

    I have itunes already installed for my ipod, now I want to sync an ipad to the same itunes can this be done and how do I do it?

  • How to efficiently get hold of N randomly selected keys out of X?

    I am writing some benchmark programs for Coherence caches and would need a way to as efficently as possible get hold of a "fairly random" selection of N keys from the cache out of the total X keys (where X >> N). With "fairly random" I am in particul

  • Dinamic image in a table

    Hallo, i have the following problems with the interactive forms in Web Dynpro for Java: 1. I would fill a table with a dynamic image. But with the script this.value.href = $record.Komponent[*].image in any row is the image that is in the last row. Is

  • Document Management within PM

    Hi, are there any sources which are giving insights and descriptions on document management within SAP PM? Does anybody have experiences with document management within PM? Best regards, Dennis

  • Upgrading Java

    Hi I'm fairly new to macs myself, so don't shoot me. Background. I have a machine that operates in non-internet connected LAN environment. These machines are required to be scanned by the InfoSec team, which is done via SSH. There is a local account,