Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OnClick - trigger Reset button?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Already talked about here

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

Closing topic
Eric
 
I just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic