Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to limit checkbox selections to one in a html document when the list containing the checkboxes is being gennerated by .js
    primarykey
    data
    text
    <p>The intent is to use an html dialog box as a settings page for a program. In this settings page, the user can create a list of salespeople that can be selected later on from a drop-down box. My goal now, is to add a checkbox that indicates witch salesperson is the default selection in that drop-down list.</p> <p>Here's what i have so far:</p> <p>This is the .js function that creates the html salespersons-table list.</p> <pre><code>function addSalespersonRow(id, name, phone, email, defsales) { var newRow = $('&lt;tr&gt;'+ '&lt;td&gt;&lt;input type="hidden" class="id" /&gt;&lt;input class="name" size="20" /&gt;&lt;/td&gt;'+ '&lt;td&gt;&lt;input class="phone" size="15"/&gt;&lt;/td&gt;'+ '&lt;td&gt;&lt;input class="email" size="30"/&gt;&lt;/td&gt;'+ '&lt;td&gt;&lt;input type="checkbox" class="defsales"&lt;/td&gt;'+ '&lt;td&gt;&lt;a href="#" onclick="$(this).parent().parent().remove(); return false;"&gt;Delete&lt;/a&gt;&lt;/td&gt;'+ '&lt;/tr&gt;'); if (id === undefined) { id = new Date().getTime(); } $('.id', newRow).val(id); if (name !== undefined) { $('.name', newRow).val(name); } if (phone !== undefined) { $('.phone', newRow).val(phone); } if (email !== undefined) { $('.email', newRow).val(email); } if (defsales !== undefined) { $('. defsales', newRow).val(defsales) } $('#salespersons-table tbody').append(newRow); return false; </code></pre> <p>This is the part of the html that displays the list.</p> <pre><code> &lt;fieldset&gt; &lt;legend&gt;Sales Person Information&lt;/legend&gt; &lt;table class="text-c" id="salespersons-table" width=100%&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Phone&lt;/th&gt; &lt;th&gt;Email&lt;/th&gt; &lt;th&gt;Default&lt;/th&gt; &lt;th&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt;&lt;/tbody&gt; &lt;/table&gt; &lt;a href="#" onclick="return addSalespersonRow();"&gt;Add new Salesperson&lt;/a&gt; &lt;input type="hidden" id="salespersons" /&gt; &lt;/fieldset&gt; </code></pre> <p>So far the only thing that's not working is that the user can select any or all checkboxes. "I need help figuring out how to limit them to one choice as the default."</p> <p>Then when the user saves the settings, this part of the .js saves the data to .dat file.</p> <pre><code>function saveSettings() { var salespersons = []; $('#salespersons-table tbody tr').each(function(){ var salesperson = '{'; salesperson += '"id"=&gt;"' + $('.id', this).val() + '",'; salesperson += '"name"=&gt;"' + $('.name', this).val() + '",'; salesperson += '"phone"=&gt;"' + $('.phone', this).val() + '",'; salesperson += '"email"=&gt;"' + $('.email', this).val() + '",'; salesperson += '"defsales"=&gt;"' + $('. defsales', this).val() + '"'; salesperson += '}'; salespersons.push(salesperson) }); $('#salespersons').val('['+salespersons.join(', ')+']'); </code></pre> <p>The .dat entry looks like this.</p> <pre><code> "defsales"on"name"Bob Summers"id"1254233372387"phone"(953) 684-9557"email"bsummers@company.com </code></pre> <p>As you can see, the checkbox for this person was checked. This value is either "on" or "". The problem i have now is that when the settings.html is reopened, the above salespersons checkbox is not checked indicating no default selection was made. So if the user does not notice this and re-saves their settings, there previous choice will be lost.</p> <p>any help you can give would be great.</p> <p>thanks for enduring my long question-explanation.</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