Question

I'm new to JavaScript and am trying to build a script that performs some data management activities(Basically query based data fetching from a database and then displaying it on a webpage).

I generally would do this on the server side with PHP and mysql but my boss want's to see a "sample" before investing in servers etc. (He has no technical knowledge regarding PHP,MySQL etc)

Now without a server I was looking for a way to build a similar system on the client side mostly via javascript. Just to demonstrate the logic I plan on implementing.

For the database part I decided to use TaffyDB, however am having issues getting an output from the database(Display the data on a webpage)

Here's my code

    <!DOCTYPE html>
      <html>
        <head>

           <script src="taffydb-master\taffy.js"></script>
           <script>

              var companies = TAFFY
                ([
                    {name:"New York",state:"WA"},
                    {name:"New Shire",state:"WE"},
                    {name:"Las Vegas",state:"NV"},
                    {name:"Boston",state:"MA"}
                ]);

              var cities = new Array();
              var cities = companies().select("name");


          </script>
       </head>

       <body>

          <script>
               document.write = (cities[1]);
          </script>


       </body>
    </html>

I know there's some silly mistake in there but really can't find it. I tried using the developer's tools (Mozilla's default one) but it returns no issues. I basically just get a blank white page when I load this file.

Was it helpful?

Solution

You are using document.write incorrectly. It is a method.

If you change your code to:

<script>
    document.write(cities[1]);
</script>

then you will get this output:

New Shire

Also, you should probably wrap the output in some element like so:

<script>
    document.write("<p>" + cities[1] + "</p>");
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top