I am trying to get for loop different textbox value in jquery function.
MY php code :
<?php
$qstid = $addnew334->id;
$dd = DB::table('tbltplatematerial')->where('qteid',$qstid)->get();
foreach($dd as $d1)
{
$ing_id = $d1->id;
?>
<tr>
<td><?php echo $d1->name;?></td>
<td><input type="text" name="txtingprice" id="<?php echo $ing_id;?>" value="" ></td>
<td><input type="checkbox" value="<?php echo $d1->id; ?>" onClick="addpriceing(<?php echo $ing_id; ?>,<?php echo $qstid;?>,<?php echo $value;?>,<?php echo $value11;?>)" id="checkid"></td>
<?php
}
?>
My jquery function:
function addpriceing(ing_id,qstid,user_product_id,temp_id)
{
var price = $("input[name='txtingprice']").val();
alert(price);
$.ajax({
url: '<?= URL:: to('addpriceing1') ?>',
type: 'GET',
//dataType: "json",
async : false,
data:{
'price':price,
'ing_id':ing_id,
'qstid':qstid,
'user_product_id':user_product_id,
'temp_id':temp_id,
},
success: function(e)
{
if(e == 0)
{
console.log("Successs");
alert("success");
}
else
{
alert('error');
}
}
});
}
I am trying to get all txtingprice value in jquery function. Please help.
Since you are creating multiple textbox using foreach so instead of name="txtingprice"
use name="txtingprice[]"
. Also you need to loop on field name to get the value as:
var price = $('input[name="txtingprice[]"]').map(function(){
return this.value
}).get()
alert(price);
<asp:TextBox runat="server" ID="reporting_person_name"></asp:TextBox >
string getValue=$('[id$=reporting_person_name]').val();
alert(getValue);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.