Note that there are some explanatory texts on larger screens.

plurals
  1. POcan't find error in my code?
    primarykey
    data
    text
    <p>I am making a simple search code. I can't find error. The error message says <code>Uncaught SyntaxError: Unexpected identifier on javascript line 40 (target=document.getElementById("outputPlace")</code>. </p> <p>Do not look at the button, I have not added event listener to it yet. I just want that when I press enter products are displayed.</p> <p>HTML CODE</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Price List &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt; PRICELIST &lt;/h1&gt; &lt;form id="formSearch"&gt; &lt;div&gt; &lt;label for="searchBox"&gt; Search products here: &lt;/label&gt; &lt;input type="text" placeholder="Type text here to search product" id="searchBox"&gt; &lt;/div&gt; &lt;div id="buttons"&gt; &lt;button id="getAll"&gt; GET ALL PRODUCTS&lt;/button&gt; &lt;/div&gt; &lt;/form&gt; &lt;div id="outputPlace"&gt; &lt;/div&gt; &lt;script src="product.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; JAVASCRIPT CODE (function(){ //start anonymous function var list= { "listOfProducts": [ { "name":"hard disk", "price": "50$", "quality":"good", }, { "name":"monitor", "price":"100$", "quality": "very good", }, { "name":"speakers", "price":"20$", "quality": "not bad", }, { "name":"headphones", "price":"12$", "quality":"bad", }, { "name": "mobile phone", "price": "300$", "quality": "excellent", }, { "name": "usb memory", "price": "30$", "quality": "the best", } ] }, var target=document.getElementById("outputPlace"), searchForm=document.getElementById("formSearch"), productList=list.listOfProducts, listLength=productList.length, searchValue=document.getElementById("searchBox"), searchInput=searchValue.value; var listMethods = { searchList: function(event) { event.preventDefault(); var i; target.innerHTML=""; if(listLength&gt;0 &amp;&amp; searchInput!=="") { for(i=0;i&lt;listLength;i++) { var product=productList[i], whatIsFound=product.name.indexOf(searchInput); if(whatIsFound!==-1){ target.innerHTML+='&lt;p&gt;'+product.name+', '+product.price+', '+product.quality+'&lt;a href="http//www.facebook.com"&gt;click here to buy&lt;/a&gt;&lt;/p&gt;' } } } }, }; searchForm.addEventListener("submit",listMethods.searchList,false); }) (); //end anonymous function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload