Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Take Hard-Coded/Repetitive jQuery Syntax and Condense to be Dynamic
    primarykey
    data
    text
    <p>I have a web page with some jQuery code. Right now I am hardcoding my jQuery syntax to accommodate for updates to 7 rows in a DB Table and also to anticipate growth of about 3 more rows. But I don't want to check my app daily to see if the DB Table has grown beyond 10 rows and then have to add more hardcoded jQuery syntax.</p> <p>Can anyone help me take my jQuery and condense it to be truly dynamic -- thus removing the hardcoded nature of it and enable it to handle any number of rows? Thanks.</p> <pre><code>&lt;style type="text/css"&gt; div.icons { clear:both; float:left; height:24px; width:30px; } div.content { height:24px; } div.show { display:block; } div.hide { display:none; } input.textbox { padding:0; margin:0; width:300px; } input.submitButton { padding:0; margin:0; vertical-align:middle; } img.button { vertical-align:middle; } &lt;/style&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#b-001').on('click', function(){ //$('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-001-on').toggle(); $('#d-001-off').toggle(); $('#d-001-off-focus').focus(); }); $('#b-002').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); //$('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-002-on').toggle(); $('#d-002-off').toggle(); $('#d-002-off-focus').focus(); }); $('#b-003').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); //$('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-003-on').toggle(); $('#d-003-off').toggle(); $('#d-003-off-focus').focus(); }); $('#b-004').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); //$('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-004-on').toggle(); $('#d-004-off').toggle(); $('#d-004-off-focus').focus(); }); $('#b-005').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); //$('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-005-on').toggle(); $('#d-005-off').toggle(); $('#d-005-off-focus').focus(); }); $('#b-006').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); //$('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-006-on').toggle(); $('#d-006-off').toggle(); $('#d-006-off-focus').focus(); }); $('#b-007').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); //$('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-007-on').toggle(); $('#d-007-off').toggle(); $('#d-007-off-focus').focus(); }); $('#b-008').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); //$('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-008-on').toggle(); $('#d-008-off').toggle(); $('#d-008-off-focus').focus(); }); // 2 extra for growth $('#b-009').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); //$('#d-009-off').hide('slow');$('#d-009-on').show('slow'); $('#d-010-off').hide('slow');$('#d-010-on').show('slow'); $('#d-009-on').toggle(); $('#d-009-off').toggle(); $('#d-009-off-focus').focus(); }); $('#b-010').on('click', function(){ $('#d-001-off').hide('slow');$('#d-001-on').show('slow'); $('#d-002-off').hide('slow');$('#d-002-on').show('slow'); $('#d-003-off').hide('slow');$('#d-003-on').show('slow'); $('#d-004-off').hide('slow');$('#d-004-on').show('slow'); $('#d-005-off').hide('slow');$('#d-005-on').show('slow'); $('#d-006-off').hide('slow');$('#d-006-on').show('slow'); $('#d-007-off').hide('slow');$('#d-007-on').show('slow'); $('#d-008-off').hide('slow');$('#d-008-on').show('slow'); $('#d-009-off').hide('slow');$('#d-009-on').show('slow'); //$('#d-010-off').hide('slow');$('#d-010-on').show('slow'); $('#d-010-on').toggle(); $('#d-010-off').toggle(); $('#d-010-off-focus').focus(); }); }) &lt;/script&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-001"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-001-on"&gt;Northside&lt;/div&gt; &lt;div class="hide" id="d-001-off"&gt;&lt;input class="textbox" id="d-001-off-focus" name="d-001-off" maxlength="50" type="text" value="Northside" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('001');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-002"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-002-on"&gt;South Lawn&lt;/div&gt; &lt;div class="hide" id="d-002-off"&gt;&lt;input class="textbox" id="d-002-off-focus" name="d-002-off" maxlength="50" type="text" value="South Lawn" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('002');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-003"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-003-on"&gt;East Wing&lt;/div&gt; &lt;div class="hide" id="d-003-off"&gt;&lt;input class="textbox" id="d-003-off-focus" name="d-003-off" maxlength="50" type="text" value="East Wing" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('003');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-004"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-004-on"&gt;West Wing&lt;/div&gt; &lt;div class="hide" id="d-004-off"&gt;&lt;input class="textbox" id="d-004-off-focus" name="d-004-off" maxlength="50" type="text" value="West Wing" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('004');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-005"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-005-on"&gt;Lobby&lt;/div&gt; &lt;div class="hide" id="d-005-off"&gt;&lt;input class="textbox" id="d-005-off-focus" name="d-005-off" maxlength="50" type="text" value="Lobby" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('005');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-006"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-006-on"&gt;Ground Floor&lt;/div&gt; &lt;div class="hide" id="d-006-off"&gt;&lt;input class="textbox" id="d-006-off-focus" name="d-006-off" maxlength="50" type="text" value="Ground Floor" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('006');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="content-wrapper"&gt; &lt;div class="icons"&gt;&lt;a id="b-007"&gt;&lt;img src="images/edit.png" alt="Edit button" class="button" title="Edit" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-007-on"&gt;TBD&lt;/div&gt; &lt;div class="hide" id="d-007-off"&gt;&lt;input class="textbox" id="d-007-off-focus" name="d-007-off" maxlength="50" type="text" value="TBD" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('update');$('#location').val('007');" title="Update" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="icons"&gt;&lt;a id="b-008"&gt;&lt;img src="images/add.png" alt="Add button" class="button" title="Add" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;div class="show" id="d-008-on"&gt;Add a new location&lt;/div&gt; &lt;div class="hide" id="d-008-off"&gt;&lt;input class="textbox" id="d-008-off-focus" name="d-008-off" maxlength="50" type="text" value="" /&gt;&amp;nbsp;&lt;input src="images/go.png" alt="Go button" class="submitButton" onclick="$('#action').val('insert');$('#location').val('008');" title="Add" type="image" /&gt;&amp;nbsp;&lt;a href="/seminars/admin/index.php"&gt;&lt;img src="images/cancel.png" alt="Cancel button" class="button" title="Cancel" /&gt;&lt;/a&gt;&lt;/div&gt; &lt;/div&gt; </code></pre>
    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.
    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