简体   繁体   中英

How to get URL parameters and pass it to an HTML output

I am making a code that requests course grades and sends them to a spreadsheet. I am familiar with Javascript; however, I am less familiar with HTML. Because not every person is taking the same courses or even the same number of courses, I wanted to send each student a custom url that contains the parameters of their name and what courses they are taking. That way the information could be populated into the HTML page and all the student would need to do is type in their grades for the corresponding courses. Then when submitted, it would send that information to a spreadsheet and handled accordingly. However, I am unsure of how I could pass parameters on to an HTML page. I am sure that it is simple but I dont know how to do it. If someone could provide some guidance it would be greatly appreciated. Below I have included the main HTML file that dictates the output. I am also including links to the other code. https://script.google.com/d/1c2XOZc5bmlnxT0ayWfYpJd4d6pKmZ8rgSiEZ-9NJ8CZIhvdjpEqSJ5X6/edit?usp=sharing

<!DOCTYPE html>
<html>
    <head>
        <base target="_top">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <?!= include('JavaScript'); ?>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-6">
                    <form id="myForm" onsubmit="handleFormSubmit(this)">
                        <p class="h4 mb-4 text-center">Input Grades Below</p>
                        <div class="form-row">
                           <div class="form-group col-md-6">
                               <label for="class001" id = "class_01" hidden>Class1</label>
                               <input type="text" class="form-control" id="grade001" name="grade00" placeholder="Grade" hidden>
                           </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="class002" id = class_02 hidden>Class2</label>
                                <input type="text" class="form-control" id="grade002" name="grade002" placeholder="Grade" hidden>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="class003" id = "class_03" hidden>Class3</label>
                                <input type="text" class="form-control" id="grade003" name="grade003" placeholder="Grade" hidden>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="class004" id = class_04 hidden>Class4</label>
                                <input type="text" class="form-control" id="grade004" name="grade004" placeholder="Grade" hidden>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="class005" id = class_05 hidden>Class5</label>
                                <input type="text" class="form-control" id="grade005" name="grade005" placeholder="Grade" hidden>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="class006" id = class_06 hidden>Class6</label>
                                <input type="text" class="form-control" id="grade006" name="grade006" placeholder="Grade" hidden>
                            </div>
                        </div>
                        <script>
                        //Script to to implement to change class labels
                        </script>
                        <button type="submit" class="btn btn-primary btn-block">Submit</button>
                    </form>
                    <div id="output"></div>
                </div>
            </div>      
        </div>
    </body>
</html>

You can use google.script.url.getLocation() to get the current URL parameters and hash.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <script>
      // URL = https://script.google.com/macros/s/SCRIPTKEY/exec?parameter=value#hash
      google.script.url.getLocation(function(location) {
        console.log(location.parameters); // {parameter: ["value"]}
        console.log(location.hash); // "hash"
      });
    </script>
  </body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM