Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recovering pre-onclick value of a radio button group

Status
Not open for further replies.

dspitzle

Programmer
Sep 9, 2003
45
US
I have a set of radio buttons, some of which can trigger the display of other form elements (i.e. the user clicks "I hate it", and the onclick property triggers Javascript which displays a textarea labeled "what do you dislike about it?"). I want to set up some validation code so that if the user types something into the revealed textarea, they can't change the radio button selection to something which would re-hide the textarea (i.e. in the example above, once they type "because it smells" into the textarea, the Javascript will prevent them from clicking on "I like it", which would subsequently hide the textarea they typed into).

Here's the problem: if multiple radio buttons could both make the textarea appear, can Javascript identify which one had been checked prior to the new onclick event? So, to use the example above, if radio buttons "I hate it" and "I don't like it much" will both display the textarea, can Javascript figure out which one had been selected prior to the user clicking on "I like it"? This is important because the validation code needs to reset the radio button group to the previous legal value, or else it's useless.
 
You can do that using Javascript. Everytime a new button is clicked call a function to put the old button id or something to a global variable.

[monkey][snake] <.
 
That suggestion already assumes the solution: by the time the onclick property has been processed, the selected radio button has already changed. If this were MS Access, I'd have the code run on the BeforeUpdate event, or something similar, but in this case the value of the radio button group has already changed by the time the Javascript can execute.
 
I'm sorry put the function on the onmousedown event handler, not on the onclick.

[monkey][snake] <.
 
Huh. Ok, I'll go take a look. If there are other suggestions, though, please feel free to post them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top