'Saving text to a txt file on a html server?

I'm building a small website and I've run into a problem. I want to save a number that is hardcoded to a .txt file on the press of a button.

I've already tried some examples online from other website but the only time I could same something was when I used PHP and it wasn't on a button press.

...
<br>
<br><table id="tblCustomers" style="width: 100%;">
    <tr>
        <td style="width: 50%;">
        <button onclick="location.href='{% url 'script' 
         %}'">Execute Script</button> <hr>
             //On this button it should save a 23 to a txt 
               file which is in the same folder and has the 
               name contacts.txt                 
        </td>
        <td style="width: 50%;"><input type="button" 
         id="btnread" value="Count Rows" /></td>
    </tr>
</table>
...

this is something else I tried it doesn't work either.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source