I am trying to achieve when user enter the id in textbox and click on submit button, to return specific status of track based on that id in txt file. So for example user enter in textbox id -> 1 and press submit button, then we read the txt file, and return back status value of that id in alert popup. What I did so far, I am getting all values from txt file by pressing the button. But how to loop through all input in txt file, and take specific value based on input from textbox?
What I have tried:
Here is my structure of traces.txt file
id,status
1,aktivan
2,neaktivan
3,aktivan
4,neaktivan
Here is my html part of code:
<form action="#" class="search-box">
<div class="input-form">
<input type="text" placeholder="Your Tracking ID" name="trackingId">
</div>
<input class="btn btn-primary" type="submit" value="Submit" id="trackButton">
</form>
And here is javascript part of code:
document.getElementById('trackButton').addEventListener('click',loadTxt);
function loadTxt()
{
fetch('traces.txt')
.then(function(response)
{
return response.text();
})
.then(function(data)
{
var jobValue = document.getElementsByName('trackingId')[0].value;
console.log(data);
alert(data);
})
}