I have the show/hide table rows function working great now (thank you), but I am having a problem with using the back button. If someone has yes to one of the items (yes/no radio buttons) the onClick event in the input tag causes the appropriate info to display. BUT when I submit the form and then hit the back button (to make corrections) then the fields are hidden even though the yes button is clicked. I tried adding the following at the top of my code to initialize them based on the value of the radio button:

function initShowHideRows(idName, clsName)
   var rgroup = document.getElementById(idName)
   var len = rgroup.length;
   if (len < 1) return;
   for (var j=0; j<len; j++)
        if((rgroup[j].value=='1')&&(rgroup[j].checked))                  showHideRows(clsName,'show'); 
        if((rgroup[j].value=='0')&&(rgroup[j].checked)) showHideRows(clsName,'hide'); 

In the code at the top of the page I have the following:

                <script language='javascript' type='text/javascript'>
                     initShowHideRows('pc_parade_float', 'vehreg');

The showHideRows function works. But the initShowHideRows doesn't seem to. Is just putting the script in the code enough or do I have to do something else to make it work?
Or have I just done something stupid or misunderstand something.
pc_parade_float is the radio group name and 'vehreg' is the class name of the rows that get toggled.

Thanks for your help.

Recommended Answers

All 6 Replies

The Back button is a curse for developer. When the button is click, the browser does not save whatever state that JavaScript has changed but reverse back to its initial state (and won't call any script on the page). If you want to control the back button, you may need to override its functionality by yourself.

Thanks Taywin. But is it possible to have a function called automatically on the page load when hitting the back button?

Unfortunately no. The only way to deal with it is that you need to control the button yourself. :(


when the back button is pressed, the previous page will be reloaded, so the onload event will be dispatched.

You need something like this:

<script language='javascript' type='text/javascript'>
    window.onload = function() {
        initShowHideRows('pc_parade_float', 'vehreg');

Hmm... Didn't know that onload will be called even with the back button. Good to know. :)


I wasn't sure either, but I did a quick test and it really does.

But you said something interesting, how could I handle the backbutton myself? Do you know which methods I would have to overwrite?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.