How to Pass string parameter in an onclick function
By FoxLearn 2/16/2024 9:37:55 AM 50
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 Add Active Navigation Class Based on URL
- How to Display popup message in Javascript
- How to Show message instead of alert
- How to fix 'Uncaught TypeError: Cannot read property 'fn' of undefined'
- How to Format numbers with commas in Javascript
- How to format number with commas and decimal in Javascript
- How to get @Url.Action url in a separate script file?
- How to use sweetalert2
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024