javascript - Replace any forward slash and or space or multiple space -


i use routine auto populate text areas in web form , works replace "forward slash / , or space or multiple space" space underscore in "input3" seo purposes.

input example: bearing 5603/zz

output result: bearing_5603_zz

<html> <head> <script type="text/javascript">     function copydata(val){       var = document.getelementbyid(val.id).value       var inputs = document.queryselectorall(".input");       for(var i=0;i < inputs.length;i++){         inputs[i].value = a;       }     }  </script> </head>  <body>  title:<input type="text" name ="title" id="text" onkeyup="copydata(this)"/><br /><br /> title input 1:<input type="text" class="input" name ="input1" /><br /> title input 2:<input type="text" class="input" name ="input2" /><br /><br /> seo input 3:<input type="text" class="input" name ="input3" /><br />                                                              </body> </html> 

you need use regex this:

<script>    function copydata(val){      var = document.getelementbyid(val.id).value;      var inputs = document.queryselectorall(".input");      for(var i=0;i < inputs.length;i++){        inputs[i].value = (i == 2) ? a.replace(/\s+/g, "_").replace(/\//g, "_") : a;      }    }  </script>  title:<input type="text" name ="title" id="text" onkeyup="copydata(this)"/><br /><br />  title input 1:<input type="text" class="input" name ="input1" /><br />  title input 2:<input type="text" class="input" name ="input2" /><br /><br />  seo input 3:<input type="text" class="input" name ="input3" /><br />


Comments