Lawl Lawl -4 years ago 98
Javascript Question

How do I keep track of all inputs that have been submitted

I'm trying to keep track every time someone submits a name using

only. How do I alert the user to let them know that the contents were posted to the website or not and what other names have been submitted.

<div id="container">
<form method="POST" action="#">
<label class="large">Please enter your name
<input id="textbox" class="name" data-name="" pattern="[a-zA-Z0-9]{1-45}">

This is the JQuery I'm using:

//When the form is submitted
//get the value of the input
var input = $('#textbox').val();

//insert it into the data-name attribute
var name = $("#textbox").attr("data-name", input);

//Aler the user


Answer Source

I think that your jquery selector is incorrect.

$("#form") means that it is targeting an element with the id of "form". In order to make that work, you would need to give your form element an id of form. E.g. <form id="form" method="POST" action="#">

In order to alert the value of the textbox however, you do not need to put the value into a data-name attribute but instead get the value out of the form when submitting.


See the following fiddle, for an example:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download