0

Trying to export an array of objects in Javascript ES6:

settings.js

const elements = [
  {
    input: document.getElementById("name"),
    required: true,
    min: 1,
    max: 100,
    type: "alpha"
  },
  {
    input: document.getElementById("addr1"),
    required: true,
    min: 1,
    max: 100,
    type: "alphanumeric"
  }
];

export default elements;

validation.js

import elements from "./settings.js";

I always get the error:

Uncaught SyntaxError: Unexpected identifier

index.html

<!DOCTYPE html>

<div id="form">
    <form action="">
        <label for="name">Name</label>
        <input type="text" id="name" name="name" placeholder="Your name..">
        <div class="error"></div>

        <label for="addr">Address 1</label>
        <input type="text" id="addr1" name="addr1" placeholder="Your first address..">
        <div class="error"></div>

        <label for="addr1">Address 2</label>
        <input type="text" id="addr2" name="addr2" placeholder="Your second address..">
        <div class="error"></div>

        <label for="city">City</label>
        <input type="text" id="city" name="city" placeholder="Your city..">
        <div class="error"></div>

        <label for="state">State</label>
        <select id="state" name="state">
            <option value="australia">Australia</option>
            <option value="usa">USA</option>
        </select>
        <div class="error"></div>

        <label for="zip">Zip Code</label>
        <input type="text" id="zip" name="zip" placeholder="Your zip code..">
        <div class="error"></div>

        <input type="button" id="confirm" value="Ok">
        <input type="button" id="cancel" value="Cancel">
    </form>
</div>

<script src="./validation.js"></script>
</body>

</html>

Cannot figure out the reason!

Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96

0 Answers0