Discussions

Expand all | Collapse all

Use a Variable in a javascript Alert box

  • 1.  Use a Variable in a javascript Alert box

    Posted 26 days ago
    I am trying to create an alert box that returns the value of a variable.  I tried using this:

    var text Danger = "<a style=\" text-decoration: none; background: #FF0000; border-radius: 5px; color: #fff; display: inline-block; width: 220px; text-align: center; padding: 8px 20px; font: normal 700 14px/1 \"Calibri\", sans-serif; text-shadow: none; \" href=\"javascript:alert(" & $message & ")\">MS Readiness</a>";

    Rather than getting a button that will trigger an alert box I an getting a button that does nothing and the button text is the value of the variable plus ")\>MS Readiness.  

    I'm guessing this is a simple syntax error, but I'm not seeing the error.


    ------------------------------
    Paul Peterson
    ------------------------------


  • 2.  RE: Use a Variable in a javascript Alert box

    Posted 26 days ago
    Edited by Evan Martinez 26 days ago
    Hi Paul,

    I just wanted to give you a heads up that javascript within your forms and buttons directly is something that we don't support and that as we continue to develop QB over time there is always the chance that javascript will break or the responses you get will potentially be inaccurate as we develop. I'm curious what this alert box that returns the valuable of a variable is doing for your work flow? Is it supposed to be altering your end user about a value on the record when they are putting in data or when opening records? Depending on what you are trying to achieve we might have some alternatives that use supported methods we can suggest. Thank you for your time today.

    ------------------------------
    Evan Martinez
    Community Marketing Manager
    Quick Base
    ------------------------------



  • 3.  RE: Use a Variable in a javascript Alert box

    Posted 26 days ago
    I am trying to display the value in a formula text field either on a button click or on hover.

    ------------------------------
    Paul Peterson
    ------------------------------



  • 4.  RE: Use a Variable in a javascript Alert box

    Posted 26 days ago
    Hi Paul,

    If you can get the value to display in a formula text or formula rich text field you could make a button which checks or unchecks a hidden checkbox field and then use form rules to have it hide or show based on a user checking/uncheck that checkbox. You could also just have the checkbox field be what the user interacts with. For example if you want a calculation to show up only when someone checks a "Form ready for submission" checkbox then you would just have the formula rich text field hidden until that checkbox gets checked. That way you don't have to use any non native features or javascript. You can potentially even set it up so the field only shows when values in a certain range are in the field if you want to remove the button step entirely.

    ------------------------------
    Evan Martinez
    Community Marketing Manager
    Quick Base
    ------------------------------



  • 5.  RE: Use a Variable in a javascript Alert box

    Posted 26 days ago
    Close, but string literal was missing the single quotes to enclose the text variable 



    var text message = "My Test Message"; var text Danger = "<a style=\" text-decoration: none; background: #FF0000; border-radius: 5px; color: #fff; display: inline-block; width: 220px; text-align: center; padding: 8px 20px; font: normal 700 14px/1 \"Calibri\", sans-serif; text-shadow: none; \" href=\"javascript:alert('" & $message & "')\">MS Readiness</a>"; $danger​

    ------------------------------
    Everett Patterson
    ------------------------------



  • 6.  RE: Use a Variable in a javascript Alert box

    Posted 26 days ago
    Evan,

    Your approach handles part of the desired results.  This will work for form view, but I would like the same functionality from the reports.  Perhaps I could use SW and create a modal.

    Everett, 

    I tried your change and have the same result.

    ------------------------------
    Paul Peterson
    ------------------------------



  • 7.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    Just for kicks, give this one a shot:  javascript:alert(\"" & $message & "\")

    It's not always the case, but there are times when using the \" in place of a single ' will make an otherwise perfect code actually function with Javascript.  They're both effectively accomplishing the same task, but the single ' can be inconsistent from time to time.


    ------------------------------
    Brad Lemke
    ------------------------------



  • 8.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    Yep, that was one of the things I tried too. same result

    ------------------------------
    Paul Peterson
    ------------------------------



  • 9.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    Alrighty, then take a close look at the $message variable contents.  It's entirely possible that the 'message' being pulled into the code contains characters that are breaking the code.

    ------------------------------
    Brad Lemke
    ------------------------------



  • 10.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    The only special character used in the message text is \n.  And, yes, the last character in the message is going to be \n.  I changed the message to equal to Left($message, Length($message) - 2), still the same result.

    ------------------------------
    Paul Peterson
    ------------------------------



  • 11.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    If you replace the $message variable with a field reference, such as [Record ID#], do you get the same error?

    ------------------------------
    Brad Lemke
    ------------------------------



  • 12.  RE: Use a Variable in a javascript Alert box

    Posted 25 days ago
    already tried that too

    ------------------------------
    Paul Peterson
    ------------------------------