Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamically populate div from js array in html form
    primarykey
    data
    text
    <p>I am basically a newbie with javascript. I want to populate a div in my webpage from a select form found on the same page, when the user selects the book and chapter he wants to view and presses the submit button. Here the code:</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; var setArray = newArray( bk1, 001, "this is my chapter content for the &lt;div&gt;", bk1, 002, "this is my chapter content for the &lt;div&gt;", bk1, 003, "this is my chapter content for the &lt;div&gt;", bk2, 001, "this is my chapter content for the &lt;div&gt;", bk2, 002, "this is my chapter content for the &lt;div&gt;" etc.... ); &lt;/script&gt; &lt;form&gt; &lt;select id="book"&gt; &lt;option value=""&gt;Select Book&lt;/option&gt; &lt;option value="bk1"&gt;Book 1&lt;/option&gt; &lt;option value="bk2"&gt;Book 2&lt;/option&gt; &lt;option value="bk3"&gt;Book 3&lt;/option&gt; &lt;/select&gt; &lt;select id="chapter"&gt; &lt;option value=""&gt;Select Chapter&lt;/option&gt; &lt;option value="001"&gt;1&lt;/option&gt; &lt;option value="002"&gt;2&lt;/option&gt; &lt;option value="003"&gt;3&lt;/option&gt; &lt;/select&gt; &lt;button id="button" type="submit"&gt;View&lt;/button&gt; &lt;/form&gt; &lt;div id="content"&gt; I want the content from the js array for the selected book and chapter to be placed here without reloading the page. &lt;/div&gt; </code></pre> <p>Note: I have simplified the code to make it a little easier to follow. I am sure my js array is incorrect and needs fixing for my purpose. Also, I don't want the page to refresh, only the div to update. Thanks for any help.</p>
    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.
    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