0
<h2><a href="#" id="addScnt">Add Another Input Box</a></h2>

<div id="p_scents">
    <p>
        <label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt" value="" placeholder="Input Value" /> <input type="checkbox" id="c_scnt" name="c_scnt" class="show"> <input type="text" id="more" name="more" class="hide"> </label>
    </p>
</div>

<span id="getall">Get all</span>

ALL CODE: http://jsfiddle.net/tZPg4/1420/

Is possible click on Get all and get all data from all inputs and next use them with loop each and get data: this.one (first input(text)), this.two (second input(checkbox)), this.three (third input - hidden )? for example:

$("#getall").click(function(){

        //here get all data to array, but how?

        array.each(function(i){
           var html = $("<tr><td>this.one</td><td>this.two</td><td>this.three</td></tr>").appendTo("#myTable");
        });

    })

LIVE: http://jsfiddle.net/tZPg4/1420/

1
  • You need to remove the id attribute from the elements you are cloning. With the code you have now, you're getting repeated ids everywhere, which is not good. Commented Feb 28, 2012 at 14:04

2 Answers 2

1

Something like this should work?

$("#getall").click(function(){
      var myRow = document.createElement("tr");

      var array = new Array()
      $.each($("#p_scents").find("p"), function(ind, elem) {
          var inputCol = new Array();
          console.log("Adding row");
          $.each($(elem).find("input"), function(ind2, inputElem) {
              if ($(inputElem).attr("type") != "checkbox") {
                 inputCol [inputCol .length] = $(inputElem).val();                  
              }
              else {
                  inputCol [inputCol .length] = $(inputElem).is(":checked");
              }
          });
          array[array.length] = inputCol;
      });
        console.log("Outputting results");
        for (var i in array) {
            console.log("Row: "+i);
            for (var j in array[i]) {
               console.log("Input: "+j + " == " + array[i][j]);         
            }                    
        }

    });
Sign up to request clarification or add additional context in comments.

4 Comments

jsfiddle.net/tZPg4/1425 please add new row and fill in. i have error: elem.val is not a function array[array.length] = elem.val();
Edited my answer appropriately - using a class on your inputs to make sure I only get the inputs you are actually after - see jsfiddle.net/tZPg4/1434 for full working jsFiddle
thanks, but in this example i dont know where input values are related. for example in first line input can be only two values, and in second line can be three values. i would like have each line in seperately variables, for example for each: this.one, this.two, this.three
all data from first line (input, checkbox, input) should be one subarray, all data from second line (input, checkbox, input) should be one subarray etc. now all data are in array - i dont know relation between this. now is array = {first, true, first, second, false}. i would like array = {array[0] = {first, true, first}, array[1] = {second, false}}
0
var arr = new Array();

$( 'input' ).each(function(index)
{
    arr[arr.length] = $(this).val();
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.