Reputation: 13
I have been working on a code and it consists of repeating the code over, about ten times to make it complete. Essentially, there are 10 occurrences of one main code.
for example, myTable1, myTable2, myTable3 .......
Instead of copying and pasting my code 10 times over and changing every single instance of "1" to "2", and then every instance of "2" to "3", and so forth
I would like to build a small program that I can load my code into and set the code to switch the numbers for me
So the first instance of loading the code into the new program would change all "1's" to "2's", and then all "2's" to "3's" and so forth, ultimately making my job tremendously easier. Hope this makes sense.
EDIT So here is a brief description of my code. Ill try my best to explain it. It is to be used for my everyday job. I'm a project manager for a roofing company, so I am expected to log daily job notes after every day of work is complete. I've created an HTML form which collects all of the information necessary for my daily job notes. The function of that form then transfers all of the information to a textarea input box where I can then copy the text and ultimately paste it into my employers daily job notes thread. The first occurrence of transferring a job as I described above, is quite simple for me. The hard part is repeating that for several more jobs in one day. I average managing about 5 to 6 jobs per day. Therefore, (as far as i know) every input and checkbox in my HTML form need a different id so that I can associate the values of the inputs and checkboxes with the correct/corresponding job note within the overall text that I will be adding to my employers daily notes thread. I know about arrays and loops but i will humbly say, I definitely don't understand either of them completely. I know what i'm doing now is bad practice and very time consuming but I haven't been able to find a work around for this particular issue. Therefore, I'm at the pOint to where I'm thinking, if I need to actually copy and edit this form and all of it's code 7 or so times, I would rather make a program that I can feed the code to and it spit the code back out after changing every instance of 1 to 2, and 2 to 3 and so forth.
Upvotes: 1
Views: 53
Reputation: 13
Actually, after thinking about this more, I realized WORD has a 'find and replace' feature (Ctrl+H)
I can paste my code in WORD, click (Ctrl+H) add the credentials for what to replace and what with, and then click 'Replace All'.
Thanks for everybody's help
Upvotes: 0
Reputation: 815
There are so many ways to get it fix one of them are as follows...
Step 1 : Create common.js file
Step 2 : Create one function which will do this logic for you. eg. CheckTheSequence(arrayObject){}
Step 3 : Update the below code as per your requirement...
// OBJECTS
var obj = { one: 1,two: 2,three: 3,four: 4,five: 5};
$.each(obj, function (index, value) {
console.log(value);
});
// Outputs: 1 2 3 4 5
Step 4: Call this common.js file into your main root page (index.html)
This way you can access this method through out the application.
Upvotes: 1