I have a table that contains rows. each rows have their own attribute called as data. I want to put all tr into a hidden input type. how can I do that?
I want to get the $('#valuePermission').val() in the server-side.
<form >
<input type="hidden" name="valuePermission[]" id="valuePermission" value=""/>
<table class='table table-hover table-striped'>
<tr data="1+a"><td>name:1</td><td>type:a</td></tr>
<tr data="2+b"><td>name:2</td><td>type:b</td></tr>
<tr data="3+c"><td>name:3</td><td>type:c</td></tr>
</table>
<button type="submit" id="btn">submit</button>
</form>
<script>
$('#btn').on('click',function(e){
e.preventDefault();
var dt=[];
$('table').find('tr').each(function(){
dt.push($(this).attr('data'));
});
$('#valuePermission').val(dt);
});
$('form').submit();
</script>
in server-side I want to have sth like this:
<?php $var=$_POST['valuePermission'];
if(isset($var && !empty($var))
$var=json_decode($var);
foreach($var as $v=>$k)
echo $v;
?>
the results is like this:
*5+sport+500001+soccer,*5+sport+500002+vollyball,*5+sport+500003+swimming,*5+sport+500004+running,*5+sport+500006+tenis,*5+sport+500007+table tenis
I want to have sth like this:
array[0]='5+sport+500001+soccer'
array[1]='5+sport+500001+vollyball and ....