1

I use this routine to auto populate some text areas in a web form and it works well I would like to replace any "forward slash / and or space or multiple space" space with a underscore for in "Input3" for SEO purposes.

Input Example: Bearing 5603/zz

Output Result: Bearing_5603_zz

<html>
<head>
<script type="text/javascript">
    function CopyData(val){
      var a = 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>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Blnukem
  • 173
  • 3
  • 13

1 Answers1

-1

You need to use RegExp for these cases:

<script>
  function CopyData(val){
    var a = 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 />
Soolie
  • 1,812
  • 9
  • 21
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252