Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make an html radio button display as selected at launch time when the stored value="on"?
    primarykey
    data
    text
    <p>Using Javascript and html:</p> <p>I have a list containing radio buttons that is dynamically loaded at launch time based on stored data. Even though the stored value of the radio is "on" the radio at launch does not display as selected.</p> <p>I cant figure out what I'm missing.</p> <pre><code>if (defsales !== undefined) { $('.defsales', newRow).val(defsales); } </code></pre> <p>defsales being the class identifier of the radio.</p> <p>Do I need an additional argument to check the value? Or, do I need to add something that reapplies the value after launch?</p> <p>I've been working at this problem long enough that I'm getting confused.</p> <p>Please excuse my ignorance,</p> <p>If it helps, here is the rest of the function:</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="radio" name="salespersons" class="defsales" /&gt;&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>Here was the code that worked correctly.</p> <pre><code>if (defsales !== undefined &amp;&amp; defsales == "on") { $('.defsales', newRow).attr('checked', true); } </code></pre> <p>Thanks to Matt, for pointing me in the right direction. </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.
 

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