Search code examples
javascriptjquerydialogtextinput

Update parent with text input value


Okay, so I have a dialog with inputs. When closing the dialog, there is a function to update the parent UL. The parent LI within that UL should have the text input value. It's not working. Please help. I put an alert in my update, to see if the value makes it there. No luck. http://jsfiddle.net/C9EbG/

jQuery

    $("input.save").click(function () {         
      $('#numbers tbody tr').each(function(i,v){            
        var ele = $(v);
        var adjName = $('input[name=adjName]',ele).val();
        parent.updateParent2(adjName);
      });
    });   
//////////////////////////////
function updateParent2(adjName){
    alert(adjName);
      var ul = $('ul.adjTabs');
      var li = ul.find('li:first').clone().val(adjName);
      li.find('li:first input');
      li.appendTo(ul)//.val(adjName);
  }

HTML

    <table id="numbers">
      <tbody>
        <tr id="cloneableRow" class="prototype">        
          <td >
          <input type="text" name="adjName" value="" class="text214 apni"/>
          </td>
        </tr>
      </tbody>
    </table>
<input type='button' value='save' class='save' />

            <ul class="tabs adjTabs">
              <li class="selected"><a href="#">Adjustments ABC</a></li>
              <li><a href="#">Adjustments DEF</a></li>
            </ul>

Solution

  • Try this: http://jsfiddle.net/C9EbG/6/

    You can see the changes here:

    $("input.save").click(function () {         
      $('#numbers tbody tr').each(function(i,v){            
        var ele = $(v);
        var adjName = $('input[name=adjName]',ele).val();
        updateParent2(adjName);
      });
    });   
    
    //////////////////////////////
    function updateParent2(adjName){
      var ul = $('ul.adjTabs');
      var li = ul.find('li:first').clone();
      li.children('a').text(adjName);
      li.find('li:first input');
      li.appendTo(ul)//.val(adjName);
    }