HOW do i get this to work
onsubmit
, instead of
onclick with a button?
I have a form:
<form id="form">
<label>Email:</label>
<input type="email" name="email" id="email" class="iput" placeholder="jane@doe.com" reguired="required"/>
<input type="button" id="nbut" onclick="loadXMLDoc()" value="NEXT">
</form>
the button works fine to call and process the javascript:
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('response').innerHTML=xmlhttp.responseText;
document.getElementById('step1').style.display = "none";
document.getElementById('step2').style.display = "block";
}
}
var em = document.getElementById('email');
var em1 = em.value;
xmlhttp.open("GET","bin/process.php?email="+em1,true);
xmlhttp.send();
}
This only works with a button onclick, I can not get it to work onsubmit and don’t know why..
onsubmitis a<form>element event.You could very simply remove the
onclickattribute from the button and change your form toThe
return falseprevents the default event handler (form submission) from executing.