Forum Discussion

PaulPeterson1's avatar
PaulPeterson1
Qrew Assistant Captain
5 years ago

Use a Variable in a javascript Alert box

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
------------------------------
  • 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
    ------------------------------
    • PaulPeterson1's avatar
      PaulPeterson1
      Qrew Assistant Captain
      I am trying to display the value in a formula text field either on a button click or on hover.

      ------------------------------
      Paul Peterson
      ------------------------------
      • EvanMartinez's avatar
        EvanMartinez
        Quickbase Staff
        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
        ------------------------------
  • 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
    ------------------------------
    • PaulPeterson1's avatar
      PaulPeterson1
      Qrew Assistant Captain
      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
      ------------------------------
      • BradLemke's avatar
        BradLemke
        Qrew Assistant Captain
        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
        ------------------------------