In advance, I say I'm a beginner. I have a problem. I want to display information from inputs but they show only for a second and disappear.
I know why: because I use <form>
.
I use <form>
because I need a button to reset the form. So, at the moment, with , the button reset works, but to display information doesn't. I tried to use another block "section" for instance and here, display button worked but reset doesnt -> because it work only with <form>
.
I've tried create a function for reset inputs, I used reset()
but it also works only with <form>
. I found out I can use preventDefault();
but I don't know this well and I don't know how it works exactly. May someone help me?
<script type="text/javascript">
function show()
{
var button = document.getElementById("press");
var name = document.getElementById("name").value;
var surname = document.getElementById("surname").value;
var mail = document.getElementById("mail").value;
var service = document.getElementById("service").value;
var mail_low = mail.toLowerCase();
button.addEventListener("submit", function(e)
{
document.getElementById("info").innerHTML = name+" "+surname+"<br/>"+mail_low+"<br/>"+"Service: "+usluga;
e.preventDefault();
}, false);
}
<form>
Name: <input type="text" id="name"/><br/>
Surname: <input type="text" id="surname"/><br/>
E-mail: <input type="text" id="mail"/><br/>
Serivce:
<select id="service">
<option>naprawa komputera</option>
<option>odzyskiwanie danych</option>
<option>problemy z oprogramowaniem</option>
<option>konfiguracja sieci LAN</option>
<option>inne</option>
</select><br/>
<input type="checkbox" checked="checked"/>Send copy information<br/>
<button type="reset" value="Reset">Reset</button>
<button type="submit" value="Send" onclick="show()" id="press">Send</button>
</form>
<p id="info"></p>