willy adams
willy adams

Reputation: 21

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.

Upvotes: 0

Views: 42

Answers (1)

Emil S. J&#248;rgensen
Emil S. J&#248;rgensen

Reputation: 6366

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.'\');"

Upvotes: 1

Related Questions