I have php foreach loop, where .data_fromCity contains different value for each element. Each item has form with input. What i want to do is to get EACH $fromCity variable value and append it to that input.
<?php foreach( $rows as $row ) : { ?>
<div class="data_fromCity"><?php echo $fromCity; ?></div>
<form><input type="text" name="cityinput" value=""></form>
<?php } ?>
I was thinking about adding to that loop something like that, but it adds text of all php items in one line for all items.
<script> $("input[name='cityinput']").val($('.data_fromCity').text()); </script>
It should be easy in jquery, but i'm not good at jquery :) Thanks for any help!
The source code what is rendered on frontend is:
<div class='wrapper'>
<div class="data_fromCity">London</div>
<form><input type="text" name="cityinput" value=""></form>
<div class="data_fromCity">Rome</div>
<form><input type="text" name="cityinput" value=""></form>
<div class="data_fromCity">Paris</div>
<form><input type="text" name="cityinput" value=""></form>
<div class="data_fromCity">Madrid</div>
<form><input type="text" name="cityinput" value=""></form>
</div>
<input type="text" name="cityinput" value="<?php echo $fromCity; ?>">?<div class="data_fromCity">to the value of the<input>just below it, right?