Backwards behaviour with html

I have a site that uses cookies and also has 2x radio buttons,  the Radio buttons when either are selected cause the Submit button on the form to enable to inhibit the choice being missed.
onClick="document.getElementById('next').disabled = false"

Open in new window


On the next screen it confirms the details and if need be offers the option to go back
onclick="history.back()"

Open in new window

.
Unfortunately, the Submit button is re-set to disable, even though the Radio button is already selected.

The other issue is that sometimes when going backwards then re-submitting, some of the changes aren't carried over, if you go back and hit submit again however it's fine. My testing on this issue initially showed it was just a timing thing.

At present the biggest issue is the onback function and avoiding disabling the Submit/Next button.

If anyone can help with either or both it'd be much appreciated.
LVL 6
kiwistagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MurfurFull Stack DeveloperCommented:
It is because you enable/disable the submit button as the result of a click
onClick="document.getElementById('next').disabled = false"

Open in new window

and by going back from the next page, the form fields retain their value i.e. checked but the click hasn't happened, so the button doesn't get disabled.

So you could add a js function to the page:
function checkSubmit(){
	if(document.getElementById("radio").checked){
		document.getElementById('next').disabled = false;
	}
	else {
		document.getElementById('next').disabled = true;
	}
}

Open in new window


substituting the id of your radio button then call the function with
<body onload="checkSubmit();">

Open in new window

or if your submit button is an image
<input type="image" alt="Submit" src="path to image" onload="checkSubmit()" />

Open in new window


The second line in the js setting disabled to true is to handle the fact that the function will load every time the page loads and not just when coming back form the next page.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kiwistagAuthor Commented:
Thanks, that worked perfectly.
As for the cookie issue, I've tried suggestions as from here, but it's inconsistent.
0
MurfurFull Stack DeveloperCommented:
You didn't mention what the cookies were doing but assuming it is related I imagine any problem is the same case as the submit button in that when you go back the page is not processed as a fresh load (or a reload) so the php doesn't parse and you cookie control does not run.

So the solution could be the same, in that you use the body onload to call functions that do the necessary - you could look at using a jQuery cookie manager like this one:

https://github.com/carhartl/jquery-cookie
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

kiwistagAuthor Commented:
Looks like the step-backwards doesn't behave the same in Chrome.
In fact even the Cookies don't behave the same in Chrome, but apparently this is common..

New coding/change of the cookies has made it so the first time has a higher chance of working the first time (sometimes not in Chrome), however when going back in Firefox, the fields are cleared but are holding in Chrome.
0
GaryCommented:
I've requested that this question be deleted for the following reason:

The question has either no comments or not enough useful information to be called an "answer".
0
MurfurFull Stack DeveloperCommented:
I beg to differ - I appreciate that the author threw back a subsequent problem but in terms of the original question and my original answer I think the author's response of "Thanks, that worked perfectly." would suggest that my answer is quite something more than "not enough useful information to be called an answer" and worthy of some points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.