Skip to content Skip to sidebar Skip to footer

How Do I Create A Button That Allows A User To Traverse Forward Through Recent Data Input By The User?

I want to have 3 buttons, Add Entry Button - This button creates a New Input box, to add onto previously created input boxes. Edit Previous Button - After creating the New Input b

Solution 1:

This should work.

var input, inputCount = 0;

functionnewInput() {
  $('#box > input').hide();
  inputCount++;
  input = $('<input>')
    .attr({
      'type': 'text',
      'placeholder': 'Entry_' + inputCount,
      'data-id': inputCount
    })
    .appendTo($('#box'));
}

functioneditPreviousEntry() {
  var cId = $('#box > input:visible').data('id');

  if (cId - 1 !== 0) {
    $('#box > input').hide();
    $('#box > input:nth-child(' + (cId - 1) + ')').show();
  }
  $('#box > input:nth-child(' + inputCount + ')').hide();
}

functioneditNextEntry() {
    var cId = $('#box > input:visible').data('id');

    if (cId + 1 <= inputCount) {
        $('#box > input').hide();
        $('#box > input:nth-child(' + (cId + 1) + ')').show();
    }
}
input {
  display: block;
  margin-bottom: 5px;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttontype="button"onclick="newInput()">Add Entry</button><buttonid="edit"onclick="editPreviousEntry()">Edit Previous Entry</button><buttonid="edit"onclick="editNextEntry()">Edit NExt Entry</button><br/><br/><spanid="box"></span><br/>

Post a Comment for "How Do I Create A Button That Allows A User To Traverse Forward Through Recent Data Input By The User?"