rupesh has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Another CGI Question from another avid perl programmer:

I have a form in a webpage. The form has a option-select(drop-down) item and a radio button. I also have a javascript which disables the select element if the radio button is clicked. And also vice-versa (ie. the radio button is disabled if the select element is changed).

The problem is, I do manipulation based on the input the user provides, and if there is any invalid data, i send him back to the previous page.
But, when I go to the previous page, say for example the select option was chosen, the radio button is also enabled, allowing the user to choose it too. Is there a way to maintain the same settings as it were earlier?

Did you ever notice that when you blow in a dog's face, it gets mad at you but when you take him on a car ride,he sticks his head out the window and likes it?

Replies are listed 'Best First'.
Re: Another Cgi Question
by bbfu (Curate) on Aug 26, 2003 at 11:54 UTC

    Without specific code examples, I can only give a general answer but, basically, when you're generating the "previous" page, you need to detect (in your Perl code) whether or not the radio button should be disabled, and give the radio button the attribute of <input disabled ...>.

    If you're using CGI for your HTML generation (I would recommend templates instead), you may need to set / clear the sticky option, as suggested by the previous answers, but probably not. (IIRC, it defaults to on, and that should work fine.)

    Update: Alternatively, you could add to your javascript onLoad handler a call to the function that disables / enables the radio button.

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: Another Cgi Question
by thinker (Parson) on Aug 26, 2003 at 10:02 UTC

    Hi rupzperl,

    If you use the CGI module for your forms, this behaviour (sticky widgets) is enabled by default. That really is the way to go.

    Hope this helps

    thinker

Re: Another Cgi Question
by jonnyfolk (Vicar) on Aug 26, 2003 at 10:12 UTC
    I'm not quite sure from your question but it seems that overriding the sticky behaviour might be useful to you. Something like:
    checkbox (-name=>'day',-checked=>1,-override=>1)
    Hope this helps you.