Like i sayed in the title, i need to build an array and change value in form input field's the code is:
<div class="row-dp">
<div class="cel-1">Obiectiv</div>
<div class="cel-2" id="obiectiv">macarale</div>
<div class="cel-3"> </div>
</div>
<div class="row-dp">
<div class="cel-1">Orasul selectat</div>
<div class="cel-2" id="orasulselectat">Bucuresti</div>
<div class="cel-3"> </div>
</div>
I need to take from " <div class="cel-2" " id to be a key and value to be value
an example
VAR['obiectiv'] = macarale;
VAR['orasulselectat'] = Bucuresti;
to transform from value in input field like
<input name="obiectiv" value="macarale" type="text" />
Thank you!
asked Jun 18, 2012 at 13:23
MiddleCloud
2101 gold badge2 silver badges16 bronze badges
2 Answers 2
$('.cel-2').each(function() {
$('input[name='+this.id+']').val($(this).text());
});
If you have to create the input elements, use this:
$('.cel-2').each(function() {
$('#yourFormNameHere').append($('<input/>').prop({'name':this.id,'type':'hidden'}).val($(this).text()));
});
answered Jun 18, 2012 at 13:29
js1568
7,0322 gold badges30 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
MiddleCloud
it create the input with value and id from the data at the last div
$('.row-dp').each(function(){
if($(this).attr('id') && $(this).attr('id')!="")
$('body').append("<input type='text' id="+$(this).attr('id')+" val="+$(this).text()+">");
});
answered Jun 18, 2012 at 13:26
Muthukumar M
1,13610 silver badges19 bronze badges
Comments
Explore related questions
See similar questions with these tags.
default
inputelements already exist or do they need to be created?