htmlformsrelative-url

How can I create a relative URL location for my form?


I'm learning about forms in HTML. At the moment I've written this part of my code:

<form action="results_page.txt" method="get">
<p>Favourite Colour:
    <input type="text" name="f_colour" size="15"
     maxlength="20" />
</form>

What I'm trying to do is use a blank local text document on notepad to receive peoples favourite colours.

At the moment I'm getting the error on Microsoft Edge:

" Hmm, we can’t reach this page. Try this •Make sure you’ve got the right URL: ms-appx-web://microsoft.microsoftedge/assets/errorpages/dnserror.html#file:///F:/HTML_practice_results.txt?username=aklsfj "

Any help would be greatly appreciated. Thank you!

p.s. I am quite new to HTML so if I am asking a dumb question, I didn't mean to :)

EDIT: My action URL is in the same folder as my HTML file.


Solution

  • Because you are loading this file directly without running it through a web server, you won't have the same access to your root folder of your web server, and everything has to be referenced from its relative location. In your example you must have results_page.txt residing in the same exact folder as whereever this HTML file lives for this to work.

    Try setting up XAMPP or a web server so that you can actually use a server-side language to read GET & POSTED data.