How to Pass string parameter in an onclick function
By FoxLearn 2/16/2024 9:37:55 AM 366
This post shows you how to pass string parameter in an onclick function javascript.
For example:
<a href="#" onclick="return getByCustomerID('+ item.customerID + ')">Edit</a>
If customerID is a string
ex. 'ABCD', 'XYZS'
You will get an error when passing value to onclick function
html render
<a href="#" onclick="return getByCustomerID(ABCD)">Edit</a>
To solve the problem, You just need to add some quotes around item.customerID
You can modify your code as shown below.
<a href="#" onclick="return getByCustomerID(\''+ item.customerID + '\')">Edit</a>
- How to get datatype in JavaScript
- How to convert string to boolean in Javascript
- How to fix 'Fetch request to https:www.google.com fails with CORS'
- How to Check Internet Connection Status in Javascript
- How to download file using JavaScript
- How to get selected option in JQuery
- How to get data attribute JavaScript
- How to Convert a String to an Integer in JavaScript
Categories
Popular Posts
Spica Admin Dashboard Template
11/18/2024