0

I'm new to html and JS and I have a form with a few fields that I need posted to a URL.

<form>
    <div>
        <label style="font-size:16px" for="title">Title:</label>
        <input type="text" id="title" maxlength="128"/>
    </div>
    <div>
        <label style="font-size:16px" for="description">Description:</label>
        <textarea id="description" maxlength="1999"></textarea>
    </div>
    <div>
        <label style="font-size:16px" for="idnumber">IDNumber:</label>
        <input type="number" id="idnumber"/>
    </div>
</form>

I need the values entered into this form to be posted to a URL that already knows how to process the input. I'm sure this is easy to do but I'm new and I'm having trouble finding a solution. Apologies for any incorrect terminology. Thanks!

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
macklin
  • 375
  • 2
  • 7
  • 18

3 Answers3

2

You have to add an action to your form tag that points to a server side script.

<form action="myscript.php" method="post">

Alternatively, you can use JavaScript to post it as an AJAX request which submits the request without a page refresh.

Collin Henderson
  • 1,154
  • 10
  • 22
2

You can use the action attribute:

<form action="some/url" method="post">
<!-- ... -->
<input type="submit" value="Submit" /> <!-- Submit button -->
</form>
ameed
  • 1,132
  • 6
  • 25
1

I'd say you're on the right track. This would be perfectly easy using basic HTML: Add an action="mySubmitPage.php" to the form element. It sounds like you want to do it without refreshing/changing the page, though (at least, that's how it sounds by "with Javascript")

That will involve an "asynchronous" submit. The fancy term is "AJAX". That part can be a lot easier using some form of Javascript framework, especially if you want to support all browser quirks. Here's an example of doing it using JQuery, for instance:

jQuery - Send a form asynchronously

Community
  • 1
  • 1
Katana314
  • 8,429
  • 2
  • 28
  • 36