0

I need to insert value of each iteration in id="funDirName" and id="addr1" and i have added the below code block for reference:

$(document).ready(function() {
                var types = [];
                var address1 = [];
                var otherTypes = [];
                $("input[id*='street_address_']").each(function(index) {
                    otherTypes.push($(this).val());
                    address1 = otherTypes[index].split(',');
                    var obj = {};
                    obj.funName = address1[0];
                    obj.addr1 = address1[1];
                    types.push(obj);
        
                    console.log("address1");
                    console.log(address1);
                    console.log(types); 
                    var funDirName = address1[index].funName;
        
                    $('#funDirName').text(funDirName);
        
                    $('#addr1').text(address1[1]);
        
                });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id = "funDirName" style = "margin: 0;" ></p>           
<p id = "addr1" style = "margin: 0;" ></p>
  • Does this answer your question? [Difference between val() and text()](https://stackoverflow.com/questions/807867/difference-between-val-and-text) – freedomn-m Jul 17 '20 at 11:30
  • `p` doesn't have a `.value` - you need to use `.text()` to set the text of a `p` - – freedomn-m Jul 17 '20 at 11:31
  • You're also using `[id*='street_address_']` but your input is `id=state_...` (unless it's created using the xsl) - please edit your code to include the *rendered* html. – freedomn-m Jul 17 '20 at 11:35

1 Answers1

0
// try to change 
$('#addr1').val(address1);
// into 
$('#addr1').text(address1);
/* val() method works only with form elements like inputs 


*/

Moufeed Juboqji
  • 690
  • 4
  • 11