Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

OnClick - trigger Reset button?

 
Chris Garrison
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is it possible to have an OnClick function (for a radio buton) do the exact same thing as the "reset" button does for a form? I have several checkboxes I want to clear when a different radio button is clicked.

Thanks.
[ May 27, 2004: Message edited by: Chris Garrison ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well, you could call the reset() method of the form, but I'm not sure that's what you really want to do. Resetting would reset all elements to their initial conditions, even the element you are clicking.

Rather, I'd recommend just changing the state of the elements you want to 'reset' individually.
 
Chris Garrison
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Bear

To back up a step - what I want is a jsp page with the following:

(radio button) Supreme Pizza
<checkbox> no onions <checkbox> no sausage <checkbox> no pepperoni ....
(radio button) Meat Lovers Pizza
<checkbox> no sausage <checkbox> no canadian bacon...
(radio button) Veggie
<checkbox> no onion <checkbox> no bell pepper...

and so on.

You select Supreme Pizza initially and select the "no onions" chechbox.

But then you change your mind and click the MeatLovers. The radio button is reset correctly but how can I automatically clear the "no onions" checkbox from the Supreme Pizza?

I've received advice on how to do this - but it all involved "hardcoding" values in the jsp - like document.form.checkbox.checked = false . The problem is that I want to load this page dynamically. If I want to add a new menu Item or ingredient, I don't want to have to change the jsp.

Another suggestion was to use a counter for naming the checkboxes. This is fine except that the response object has "no checkbox15" instead of "no onions" when subsequent jsps are called which doesn't do me much good either. Am I missing something?

Of course I could hard code the script stuff, but I don't want to have to reprogram the jsp every time the menu changes.

Maybe this isn't even possible. I'm lost. Thanks for the help.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Cannot the same mechanism used to dynamically populate the page with the controls populate a Javascript function with appropriate statements?
 
Chris Garrison
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Bear Bibeault:
Cannot the same mechanism used to dynamically populate the page with the controls populate a Javascript function with appropriate statements?


I don't know? I guess that' my question. I'm very much a rookie at javascript.

Can you send an array of Objects as an argument to a javascript function?

Maybe I need some beginner reading material.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
I highly recommend the Flanagan book.

The way I would approach this is to figure out what I'd want the Javascript to be if I were going to hard-code it into the page, and then use the same data that was used to dynamically generate the controls to generate the matching Javascript.

It's also possible to try a less specific appraoch. If your Javascript logic can differentiate what the "current" set of check boxes (that are not to be disbaled) are, it can loop through the form looking for all checkboxes and disable all but the "current" set.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
Already talked about here

http://www.coderanch.com/t/114738/HTML-JavaScript/Clearing-checkboxes

Closing topic
Eric
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic