'how to pass values inside javascript function along with this

This is my code where I pass value:

echo '<td style="width:10px;" ><input type="text" name="qty__'.$product_name.'" id="qty__'.$product_name.'"  onkeyup="total_amounts(this,'.$product_name.');"  /></td>';

i just only want onkeyup function take this and also product name which will be used in below code

<script>
   function total_amounts(qty,product_id)
 {   
 alert('hi');
var product_id = document.getElementById("discount1").value;

   alert(product_id);
 var price1 = document.getElementById("price1__"+product_id).value;
  var discount1 = document.getElementById("discount1__"+product_id).value;
 alert(discount1);

    document.getElementById('net_price').value = price1;

    }
  </script>

but the problem is I have not received the product name inside the script.



Solution 1:[1]

Maybe you are forgetting to put strings in quotes?

Escaping ' by using a backslash \' allows you to do this.

onkeyup="total_amounts(this,\''.$product_name.'\');"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Emil S. Jørgensen