How to Pass string parameter in an onclick function
By FoxLearn 2/16/2024 9:37:55 AM 226
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 Convert a String to an Integer in JavaScript
- How to use getday in Javascript
- How to use repeat in Javascript
- How to use regexp in javascript
- How to get url parameter in javascript
- How to Format numbers with commas in Javascript
- How to format number with commas and decimal in Javascript
- How to check if string contains in javascript
Categories
Popular Posts
How to implement Jint in C#
09/14/2024
How to Download Chromedriver for Selenium
09/14/2024