0

I work in schools and use google forms to keep track of a number of things. One of these forms emails people with information from the sheet that is entered. I have managed to cobble together a good script that provides this service, however, I want it to look good.

My question is simple (or so I believe it is): When I put in my HTML for the body of the email, how do I call the variables that I have defined earlier in the script?

Do I need to define them in the HTML or can I call them from the JavaScript?

I am not a serious coder by any means but this one has seemed to escape my ability to google it.

Any help would be appreciated.

4
  • please add code to your question. Commented Sep 25, 2017 at 13:29
  • 1
    I believe you would need to evaluate the variables before they go into the body (and get emailed). Most, if not all, email clients block any sort of javascript from running in the email body. Commented Sep 25, 2017 at 13:33
  • Please paste the HTML you are writing as well as this script you are talking about, also highlight what variables do you need and where do you need them. Commented Sep 25, 2017 at 14:32
  • "...however, I want it to look good." Ok, that would be CSS more than JavaScript. Are you limited and can't use CSS because some or all of your clients use Outlook to read their mail? Commented Sep 25, 2017 at 14:55

2 Answers 2

1

calling a value of the variable created in javascript, outside the script.

    <html>
    <script>
    var somevariable = "hi"; //this is the variable you create in JavaScript

    window.onload = function() {

       document.getElementById("blabla").innerHTML = somevariable; //here you send the value of 'somevariable' to html.
    } 
    </script>
    <body>
    <input type="text" id="blabla" name="someInput"></input>
    </body>
    </html>
Sign up to request clarification or add additional context in comments.

Comments

0

I am not too sure what your code looks like so this is only an attempt to answer what I understand so far.

In you HTML document you don't call variables, you call functions. for example when you click a button, the text would change to what your variable is by calling the onclick Event inside the button, ChangeText() will be the function for the first example:

<!DOCTYPE html>
<html>
    <body>
        <p id="p1">Hello</p> <br />
        <button onclick="ChangeText()">Button</button> <!-- onclick event -->

        <script>
            var p1 = document.getElementById("p1"); //variable created

            function ChangeText () {
                //when you click the button this function will be called
                p1.innerHTML = "Changed text on button click!";
            }
         </script>
    </body>
</html>

You could also call on the load of the document (but this would mean that you would't see what it was before):

<!DOCTYPE html>
<html>
    <body>
        <p id="p1">Hello</p> <br />

        <script>
            var p1 = document.getElementById("p1"); //variable created
            p1.innerHTML = "Changed text on page load!"; //change text on load
         </script>
    </body>
</html>

hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.