Note that there are some explanatory texts on larger screens.

plurals
  1. POSet the value of a radio button to be the text from the closest input text via jquery
    primarykey
    data
    text
    <p>I have a form where I am adding form elements dynamically. The elements I am adding are a text field and a radio button. Now, I want the value of the selected radio button to be the text the user has typed on the adjacent input box. Here is the JS:</p> <pre><code>var $node = ""; var varCount=0; $('body').on('click', '.removeVar', function(){ $(this).parent().remove(); varCount--; }); $('#addfld').on('click', function(){ varCount++; $node = '&lt;label for="losfldlbl[]"&gt;Field Name '+varCount+': &lt;/label&gt;' + '&lt;input type="text" name="losfldlbl[]" id="losfldlbl[]" title="Custom field name cannot be blank" required=true placeholder="Field name'+varCount+'"/&gt;'+ 'Is this the value field? &amp;nbsp;&lt;input type="radio" name="losvaluefld[]" id="losvaluefld[]" value=false /&gt;&amp;nbsp;&amp;nbsp;'+ '&lt;span class="removeVar label label-important"&gt;&lt;a id="removeFld" href="#" title="Click here to remove this field"&gt;&lt;i class="icon-minus icon-white"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;'; $(this).parent().before($node); }); $('input:radio').click(function() { $(this).attr('value', $(this).prev().attr("value")); alert($(this).val()); }); </code></pre> <p>and here is my HTML:</p> <pre><code>&lt;form id='myForm'&gt; click on the yellow button custom fields &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class='label label-warning'&gt;&lt;a id='addfld' href='#' title='Click here to add a new field'&gt;&lt;i class='icon-plus icon-white'&gt;&lt;/i&gt;&lt;/a&gt;&lt;/span&gt;&amp;nbsp; &lt;/form&gt; </code></pre> <p>I have shared a <a href="http://jsfiddle.net/Pyj7K/1/" rel="nofollow">JsFiddle here</a>. The problem is that I cannot get the value passed from the input text to the radio button's value.</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