I am trying to input through a form and when I submit the button, it is not working. Kindly help me with this. I want to display the input taken from the form and display it in the span tags at the bottom.
Below is my HTML and JavaScript:
// Variables are being declared.
var sRecipientName;
var sOrganizationName;
var sDate;
var sURL;
var sHostName;
function submitDetails() {
sRecipientName = document.getElementById("recipient").value;
console.log(sRecipientName);
sOrganizationName = document.getElementById("organization").value;
console.log(sOrganizationName);
sDate = document.getElementById("date").value;
console.log(sDate);
sURL = document.getElementById("URL").value;
console.log(sURL);
sHostName = document.getElementById("host").value;
console.log(sHostName);
}
<section id="pageForm">
<form action="#">
<label for="recipientName">Recipient name:</label>
<input type="text" id="recipient" name="recipientName" placeholder="Enter your Recipient Name" />
<label for="organizationName">Organization name:</label>
<input type="text" id="organization" name="organizationName" placeholder="Enter your Organization Name" />
<label for="eventDate">Event Date:</label>
<input type="text" id="date" name="eventDate" placeholder="Enter your Event Date" />
<label for="websiteURL">URL:</label>
<input type="text" id="URL" name="websiteURL" placeholder="Enter your Website URL" />
<label for="hostName">Host name:</label>
<input type="text" id="host" name="hostName" placeholder="Host Name" />
<input type="submit" value="Submit" onclick="submitDetails()">
</form>
</section>
<article id="placeholderContent">
<span id="recipientName">recipientName</span>!
<br/>
<br/> <span id="organizationName">organizationName</span> <span id="eventDate">eventDate</span> <span id="websiteURL">websiteURL</span>
<br/>
<span id="hostName">hostName</span>
</article>
input type="submit"button the form is submitted to the server and the page is re-loaded. If you were actually writing your vars to the page, not just to the console, they would disappear when the page got loaded again after the submit. Again as Davis says, you will need to prevent that default form submission behavior.