/    Sign up×
Community /Pin to ProfileBookmark

Browser Back click issue with JS

Hi
I am held up with the following ussue. please help..

Situation
There are 5 checkboxes . only maximum of 3 check box can be selected.
i have an onchange function to disable the other 2 checkbox if 3 checkbox is selected and thts working fine

Problem

if i check 3 selectbox then the other 2 will be disabled. and then if submit this page to another page and from that page if i click the BROWSER BACK BUTTON,
then the page will come back to the first page with 3 checkbox checked but the rest 2 will be ENABLED !

the issue happening here is the js function iam using to disable the checkbox is not firing properly.!

I have called the function on page . i have used a DEFER option also in the script to execute js after html is rendered.

but for some reason THE JS FUNCTION IS NOT DETECTING THE USER CHECKED OPTIONS while coming back to the page from browser back click. ?

hope i will get a solution here.

Thanks,
Dev

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@salmanshafiqOct 04.2007 — put your page code here i'll sort this problem for you
Copy linkTweet thisAlerts:
@devloshauthorOct 04.2007 — Here is my Code:

<script language="javascript" defer>

function fun1(chkbox_name,frmName)

{

var iSpecCount = 0;
var frmObj = eval('document.' + frmName)
var chkval = eval('frmObj.' + chkbox_name);

for(i=0; i < chkval.length; i++)
{
if(chkval[i].checked == true)
{
iSpecCount = iSpecCount + 1;
}
}
if(iSpecCount >= 3)
{
fun2(chkval,true);
}
else
{
fun2(chkval,false);
return;
}
return;
}
function fun2(Togglechkval,chkStatus) {
for(i=0; i < Togglechkval.length; i++) {
if(chkStatus) {
if(Togglechkval[i].checked != chkStatus)
Togglechkval[i].disabled = chkStatus;
}
else
Togglechkval[i].disabled = chkStatus;
}

}
fun1('chkbox','frmTest');

</script>

<form action="test1.cfm" method="post" name="frmTest">

<input type="checkbox" value="1" name="chkbox" onClick="fun1('chkbox','frmTest')">

<input type="checkbox" value="2" name="chkbox" onClick="fun1('chkbox','frmTest')">

<input type="checkbox" value="3" name="chkbox" onClick="fun1('chkbox','frmTest')">

<input type="checkbox" value="4" name="chkbox" onClick="fun1('chkbox','frmTest')">

<input type="checkbox" value="5" name="chkbox" onClick="fun1('chkbox','frmTest')">

<INPUT type="submit" value="check it !">

<span>asdfasfasdf</span>

</form>
Copy linkTweet thisAlerts:
@salmanshafiqOct 04.2007 — which browser are you using please tell me with version
Copy linkTweet thisAlerts:
@devloshauthorOct 04.2007 — internet explorer 6.0
Copy linkTweet thisAlerts:
@salmanshafiqOct 04.2007 — the problem is in your browser not in the code it's working fine on Internet Exploere 6.0.2900.2180
Copy linkTweet thisAlerts:
@devloshauthorOct 04.2007 — but i am using IE 6.0.3790.

dont know whether u are looking for the currect issue. the issue is not for the functionality in the first load of the page. that is working fine.

but when i submit this page to a second page and if i click the browser back button to return back to the first page. then the check box is not staying greyed ! thts the problem.

what my requirement is when i click back button and return to the page then also the 2 check box should be GRAYED OR DISABLED.
×

Success!

Help @devlosh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...