On my invoice form, users have the ability to click on a button to add as many parts as the want and then the code below automatically fills in the part description and part price.
I tried to loop it but its not working, instead i added multiple scripts for partnumber1, partnumber2, partnumber3 etc.
<script type="text/javascript">
$( "#partstable" ).on( 'blur keyup', "#partnumber" , function() {
searchString=$(this).val();
var data = 'partnumber='+searchString;
if(searchString) {
// ajax call
$.ajax({
type: "POST",
url: "partpricequery.php",
data: data,
success: function(html){
result = String(html).split("|"),
$("#partdescription").val(result[0]);
$("#partprice").val(result[1]);
showlabel ();
}
});
}
return false;
});
</script>
2nd one
<script type="text/javascript">
$( "#partstable" ).on( 'blur keyup', "#partnumber1" , function() {
searchString=$(this).val();
var data = 'partnumber='+searchString;
if(searchString) {
// ajax call
$.ajax({
type: "POST",
url: "partpricequery.php",
data: data,
success: function(html){
result = String(html).split("|"),
$("#partdescription1").val(result[0]);
$("#partprice1").val(result[1]);
showlabel ();
}
});
}
return false;
});
</script>
3rd
<script type="text/javascript">
$( "#partstable" ).on( 'blur keyup', "#partnumber2" , function() {
searchString=$(this).val();
var data = 'partnumber='+searchString;
if(searchString) {
// ajax call
$.ajax({
type: "POST",
url: "partpricequery.php",
data: data,
success: function(html){
result = String(html).split("|"),
$("#partdescription2").val(result[0]);
$("#partprice2").val(result[1]);
showlabel ();
}
});
}
return false;
});
</script>
This is how i tried to loop it but again its not working
<script type="text/javascript">
var count = 0;
$( "#partstable" ).on( 'blur keyup', "#partnumber"+count , function() {
searchString=$(this).val();
var data = 'partnumber='+searchString;
if(searchString) {
// ajax call
$.ajax({
type: "POST",
url: "partpricequery.php",
data: data,
success: function(html){
result = String(html).split("|"),
var counter=0;
loop{
$("#partdescription"+counter).val(result[0]);
$("#partprice"+counter).val(result[1]);
counter++;
}
showlabel ();
}
});
}
return false;
});
</script>