String replace all function in javascript


Example:

Enter comma separated value
Replace comma with
Output



Code Sample:

<html> <head> <title>String replace all function in JavaScript</title> <script language="Javascript" type="text/javascript"> function replacestr() { try { var input = document.getElementById("txtinput").value; var newchar = document.getElementById("txtnewchar").value; var output = input.replace(/,/g, newchar); document.getElementById("txtoutput").value = output; } catch (err) { alert(err.Description); } } </script> </head> <body> <table align="center"> <tr> <td> Enter comma separated value </td> <td> <input type="text" id="txtinput" /> </td> </tr> <tr> <td> Replace comma with </td> <td> <input type="text" id="txtnewchar" /> </td> </tr> <tr> <td colspan="2" align="center"> <input type="button" value="Replace" onclick="replacestr();" /> </td> </tr> <tr> <td> Output </td> <td> <input type="text" id="txtoutput" /> </td> </tr> </table> </body> </html>