Reputation: 1153
I have this function, but I want to disable the refresh of the page.. I have I button and when I click it it shows the second form and hide the first one... But it shows the second form just for a second, and then display the first form again. I think it is reloading the page...But is there any way to stop it.. this is my function
function displayform2() {
/*For desktop*/
var inputs = [
document.getElementById('firstname1'),
document.getElementById('lastname1'),
document.getElementById('cel1'),
document.getElementById('email1'),
];
var nr = 0; /*to keep the number of fields empty*/
for (var i = 0; i < inputs.length; i++)
if (inputs[i].value == '') {
nr++;
}
if (document.getElementById('desktop1').style.display == 'block') {
if (nr > 0) {
document.getElementById('totalfield1').style.display = 'block';
} else {
document.getElementById('desktop1').style.display = 'none';
document.getElementById('desktop2').style.display = 'block';
document.getElementById('desktop3').style.display = 'none';
}
}
HTML
<input type="button" value="Proceed" id="submit1" onclick="displayform2()" class="button" style=" margin-top: -40px;margin-left: 60%;width: 25%" disabled>
I am using these button
Please help me
Upvotes: 0
Views: 1451
Reputation: 13796
Show us the HTML. Are you using an anchor to call the displayform2() function?
If so, make sure to use return false; to prevent the default behaviour (which is to navigate)
<a href="javascript:displayform2(); return false;">Display form</a>
Upvotes: 1