Sunday, 18 August 2013

replacing , with / in javascript

replacing , with / in javascript

I am trying to replace comma with / in javascript and written below code.
There are multiple text box available in the form. I want to write a
single function and call them on all the text fields.
The issue that I am experiencing is that I am not able to send the current
ID to javascript method. How to achieve this? thank you.
function removeComma(val)
{
var values = document.getElementById('val').value; //Object Required
Error
var n=values.replace(/,/, "/");
document.getElementById('val').value=n;
}
<input type="text" id="one" name="one" onkeypress="removeComma(this)">
<input type="text" id="two" name="two" onkeypress="removeComma(this)">
<input type="text" id="three" name="three" onkeypress="removeComma(this)">
Ther error that I am getting from above code is "OBJECT REQUIRED" at first
line.

No comments:

Post a Comment