File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes OnClick - trigger Reset button? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic
Author

OnClick - trigger Reset button?

Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
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 ]

May the force be with you, always.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
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

Joined: Jan 10, 2002
Posts: 60794
    
  65

Cannot the same mechanism used to dynamically populate the page with the controls populate a Javascript function with appropriate statements?
Chris Garrison
Ranch Hand

Joined: Jun 13, 2002
Posts: 44
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

Joined: Jan 10, 2002
Posts: 60794
    
  65

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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.
 
subject: OnClick - trigger Reset button?
 
Similar Threads
Check a checkbox after hitting a reset button
Selected radio button value to be send to action class
Onclicking the radio buttion how to clear the populateTable() data in javascript
How Will Revision on JSP would take effect?
Java Script Onclick event with pre selected radio buttons