How can the use of the browser back button be prevented?
I have a web-form that has a series of chained select lists. If the customer is using Internet Exploder and presses the browser back button the select lists are partially selected. The problem is that the validation fails to catch the missing value so the web-form is able to be submitted without the required field. I understand that with Internet Exploder, the scripts are not re-run when you press the back button.
With both Chrome and Firefox the fields remain intact, but the customer has standardized on Internet Exploder.
I have found several post on the subject on the Web:
https://forums.asp.net/p/1548663/3793731.aspx#3793731
As you will find out…they all have something in common. Either it cannot be done or they say don’t. Basically, they all suggest to change the behavior of the Back button but not to lock it.
Hope thoses helps.
After reading a bunch, I’m thinking that a better approach would be to add a small javascript function to test for empty values on submit.
<button value=“submit” name=“submit” type=“submit” onclick=“submitForm()” >Submit Print Request</button>
function testSubmit()
{
var x = document.forms[“eformsubmit”][“ClientName”];
var y = document.forms[“eformsubmit”][“LOB”];
if(x.value ==“” || y.value==“”)
{
alert(‘Not allowed!!’);
return false;
}
return true;
}
function submitForm()
{
if(testSubmit())
{
document.forms[“eformsubmit”].submit(); //first submit
document.forms[“eformsubmit”].reset(); //and then reset the form values
}
}
I haven’t tried it in PP Connect yet, but think that it will do the trick. They would be able to use the back button, but I should be able to catch the missing field.
This seems to work better. In my case the “ClientName” is the issue. I pop up an alert and then reload the page if the value is empty. Could be frustrating if that is the field you missed the first time around, but the HTML validation should catch it before this point. (hopefully)
function validateForm() {
var x = document.getElementById(‘ClientName’).value;
if (x == null || x == 0 || x == “0”) {
var r = confirm(“The Backbutton is not allowed, Reload Form?”);
if (r == true) {
location.reload();
} else {
document.getElementById(“ClientName”).focus();
}
}
else
document.form.submit();
}