im trying to add a new element every button click and i want to post their values in php... so far ive started coding but i think im lost..
我试图添加一个新的元素每个按钮点击,我想在PHP发布他们的价值...到目前为止,我开始编码,但我想我失去了..
here is my jquery that adds new element
这是我的jquery添加新元素
//this is the button that adds new element
$('#addnew').click(function(){
$("<input type='text' class='in'/><br>").appendTo('#d');
});
and here is my method to post the value
这是我发布价值的方法
$('#save').click(function(){
$('#resultdiv').load('myphp.php',{Values: <!--i dont know what to pass here--> });
});
and here is my php
这是我的PHP
<? echo"$_POST[Values]";?>
this portion is where the elements are added
这部分是添加元素的地方
<div id='d'>
<!--ADDED ELEMENTS WILL GOES HERE-->
<input type='button' id='addnew' value'ADD NEW'>
<input type='button' id='save' value='save'>
</div>
and here is the div for the reult
这是reult的div
<div id='resultdiv'>
</div>
please help me how to figure this out..thanks
请帮我解决这个问题。谢谢
2 个解决方案
#1
1
Put inside the click this statement which will update the value of the input type via "ID"
点击此语句,将通过“ID”更新输入类型的值
i=0
$('#ElementName'+i).value(Value_Variable);
i++;
Let me know if there is a problem
如果有问题,请告诉我
--updated the answer
- 更新了答案
#2
0
serialize the values using serialize
and then convert them to array using makeArray
使用serialize序列化值,然后使用makeArray将它们转换为数组
var ser = $(".in").serialize();
$('#save').click(function(e){
e.preventDefault();
$('#resultdiv').load('myphp.php',{Values: $.makeArray(ser) });
});
dont know much about the php stuff but you can try the following code
不太了解PHP的东西,但你可以尝试以下代码
foreach ($_POST['Values'] as $key => $val) {
echo $val;
}
#1
1
Put inside the click this statement which will update the value of the input type via "ID"
点击此语句,将通过“ID”更新输入类型的值
i=0
$('#ElementName'+i).value(Value_Variable);
i++;
Let me know if there is a problem
如果有问题,请告诉我
--updated the answer
- 更新了答案
#2
0
serialize the values using serialize
and then convert them to array using makeArray
使用serialize序列化值,然后使用makeArray将它们转换为数组
var ser = $(".in").serialize();
$('#save').click(function(e){
e.preventDefault();
$('#resultdiv').load('myphp.php',{Values: $.makeArray(ser) });
});
dont know much about the php stuff but you can try the following code
不太了解PHP的东西,但你可以尝试以下代码
foreach ($_POST['Values'] as $key => $val) {
echo $val;
}