0

I have javascript file named w1.js, in the code there is a

 var IDInput = '1'; .

I would like to generate few hundred .js files, changing only that value and save them as separate file.

Like:

w2.js file with var IDInput = '2';

w3.js file with var IDInput = '3'...so on.

Using the software fileboss I'm able to generate duplicates of the same .js file as I wanted, w1.js,w2.js,w3.js..but changing the code "var IDInput = 'x';" in them manually using notepad++ is a lot, the number in the name of the file and the value of the variable needs to match.

Please note "var IDInput = '1';" is on line 10 in my code, so replacing the line could be an option using a tool or I can set it as a unique string (many other variables are in the code that need to remain intact).

Any ideas?

Gaal Csaba
  • 37
  • 5
  • This sounds very much like an X/Y problem. Why not use just one script and dynamically determine which `IDInput` is needed? A more elegant solution could probably be produced if you explain how you're intending to use this – CertainPerformance Dec 23 '18 at 12:21
  • I'm working on a price comparison website and for each product/page it will run a different .js file to show the price tags and shops, which is requested from the API based on the "id". The id of the product won't appear on the page, so making it dynamic linking to it, it's not really an option. I know many of you would disagree using Wordpress+ a js file per page, and also sounds insane, but it works quite well, the only issue is..it will take days till I manage to change the values manually for all of them. – Gaal Csaba Dec 23 '18 at 12:42
  • 1
    You might consider checking the page location and then assigning the `IDInput` based off of that, only one script required – CertainPerformance Dec 23 '18 at 12:49
  • Thank you, it makes sense, I will try to approach it that way. – Gaal Csaba Dec 23 '18 at 12:52

0 Answers0