Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <!--
- changes:
- v240316b v05c Added [text1] and [text2] and SORT tags to replace with static text
- v240314b v05b
- -->
- <title>Number Sequence Generator</title>
- </head>
- <body>
- <label for="sentence">Enter sentence:</label>
- <input type="text" id="sentence" name="sentence" value="test[x]bbbb[entry]vvvv[x]"><br><br>
- <label for="num_lower">Lower Number:</label>
- <input type="number" id="num_lower" name="num_lower" value=1 ><br><br>
- <label for="num_higher">Higher Number:</label>
- <input type="number" id="num_higher" name="num_higher" value=15 ><br><br>
- <label for="textadd1">Enter text1 for replacing a [text1] tag :</label>
- <input type="text" id="textadd1" name="textadd1"><br><br> <!-- Added text input for replacement text -->
- <label for="textadd2">Enter text1 for replacing a [text2] tag :</label>
- <input type="text" id="textadd2" name="textadd2"><br><br> <!-- Added text input for replacement text -->
- <label for="zero_padding">Zero Padding:</label>
- <input type="checkbox" id="zero_padding" name="zero_padding"><br><br>
- <label for="sort_result">Sort Result:</label>
- <input type="checkbox" id="sort_result" name="sort_result" checked ><br><br>
- <button onclick="generateSequence()">Generate Sequence</button><br><br>
- <textarea id="result" rows="10" cols="50"></textarea>
- <script>
- function generateSequence() {
- var sentence = document.getElementById('sentence').value;
- var num_lower = parseInt(document.getElementById('num_lower').value);
- var num_higher = parseInt(document.getElementById('num_higher').value);
- var textadd1 = document.getElementById('textadd1').value; // Get the text for replacement
- var textadd2 = document.getElementById('textadd2').value; // Get the text for replacement
- var zero_padding = document.getElementById('zero_padding').checked;
- var sort_result = document.getElementById('sort_result').checked; // Check if sort result is checked
- var result = '';
- //let lineIndex = 0;
- for (var i = num_lower; i <= num_higher; i++) {
- (function(i) {
- var num = zero_padding ? String(i).padStart(String(num_higher).length, '0') : i;
- var entry = sentence.replace(/\[x\]/g, num);
- entry = entry.replace(/\[text1\]/g, textadd1); // Replace [text] with the contents of textadd1
- entry = entry.replace(/\[text2\]/g, textadd2); // Replace [text] with the contents of textadd1
- //console.log("entry=" + entry + " num=" + num);
- if (entry.includes('[entry]')) {
- fetch('entries.txt').then(response => response.text()).then(text => {
- var lines = text.split('\n');
- //console.log("entry222222222=" + entry + " num=" + num + " i=" + i);
- var entryWithEntries = entry.replace(/\[entry\]/g, lines[i-1] || '');
- //console.log(lines);
- //console.log("entry3333333=" + entry + " num=" + num + " i=" + i);
- result += entryWithEntries + '\n';
- document.getElementById('result').value = result;
- });
- } else {
- result += entry + '\n';
- document.getElementById('result').value = result;
- }
- })(i);
- }
- if(sort_result) {
- //console.log("sort_result="+sort_result);
- setTimeout(() => {
- // Your code after pausing for 1 second
- var textArea = document.getElementById('result');
- var text = textArea.value;
- var sortedText = text.split('\n').filter(line => line.trim() !== '').sort().join('\n'); // Sort the text lines alphabetically & // Remove empty lines
- textArea.value = sortedText; // Update the textarea with the sorted text
- }, 1000); // 1000 milliseconds = 1 second
- }// end of if(sortResult) {
- } //end of function generateSequence()
- </script>
- </body>
- </html>
- <pre>
- ```
- Hello[x]σδδασδ[x]d[entry]sada
- Make sure to create a file named `entries.txt` containing the strings you want to replace `[entry]` in the sentence with.
- I want a single html page with included javascript that will have a text input named "sentence".
- Then it will have two more text inputs named num_lower and num_higher. At the bottom will have a submit button and a text area for the output/result . When I press the submit button I want the script to generate a sequence of numbers between num_lower and num_higher. Then I want in the result textarea to show one entry for each number. Each entry will be the text entered in the "sentence" text input where we will replace all instances of string "[x]" with the current generated number.
- I also want a check box to select if we want the numbers to be prefixed with zeroes so they are always the same character size as the number in input "number_higher" (eg 001,002,...,100). I also want another feature: if in the sentence text we have the string [entry] then the script wil read the file "entries.txt". This file will contain a string in each line. I want each [entry] to be replaced by the string contained in the current line of the file "entries.txt" , then we move to the next line of entries.txt
- sample entries.txt
- aaaaa
- bbbbb
- ccccc
- ddddd
- eeeee
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement