Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a small searchable database with JavaScript Object Arrays only. No AJAX, no PHP
    primarykey
    data
    text
    <p>I want to create a small database, or collection, of items - only about 30 - you can search with JavaScript alone.</p> <p>For example - let's say I have 20 houses to rent and I want students to be able to search for them houses with 4 or 5 rooms. </p> <p>I can create the house objects like this:</p> <pre><code>function house(address, rooms, bathrooms){ this.address=address; this.rooms=rooms; this.bathrooms=bathrooms; } var property1 = new house("10 Park Way","4","1"); var property2 = new house("61 Park Avenue", "5","2"); var property3 = new house("585 Park Road", "3", "1"); </code></pre> <p>I want to be able to search this list by "rooms" and display the address, number of rooms and number of bathrooms.</p> <p>NB: I know the way I've written it isn't an Array but I will use an Array so I can use a for loop to cycle through the properties and evaluate them in the following way:</p> <pre><code>if(property[i].rooms == roomquery){ document.write('Address:' + property[i].address + '.&lt;p&gt;'); document.write('Address:' + property[i].rooms + '.&lt;p&gt;'); document.write('Address:' + property[i].bathrooms + '.&lt;p&gt;'); } </code></pre> <p>Simple eh?</p> <p>Except I don't know how to pass the roomquery variable from my form to my script.</p> <p>The order of the process is: Search Page -> Results Page -> Details Page</p> <p>The user searches and gets a list of results. There is the option to view the property in more detail on the result page, passing the data from the results to page to be reformatted on a details page. Of course there will be much more data about each property in the Array and I can give this data to the id or value properties of invisible tags for collection and resubmission to a script on the details page.</p> <p>I know I can do this with PHP, and I know I could do this by sending the roomquery variable to a script on the same page and making the changes on the Search Page.</p> <p>But what I want to do is send the data, which is just a single number, to a script on the Results Page using GET, or any other method, because that way I can run the search from any page that will send to the Search Page.</p> <p>I've searched the internet for this and I'm not coming up with anything. There must be a way.</p>
    singulars
    1. This table or related slice is empty.
    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