aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Check a checkbox after hitting a reset button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Check a checkbox after hitting a reset button" Watch "Check a checkbox after hitting a reset button" New topic
Author

Check a checkbox after hitting a reset button

Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Hi all,

I have two radio buttons:


This below is the reset button in the form:


What I want to do when user clicks the "Reset selection" button, I want to check the historicalTimeDataOption checkbox. But it doesn't seem to work. The checkbox is unchecked after I press the reset button.
Here's my function:


Thanks in advance for all the help. Don't hesitate to let me know if I can provide with more information.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
You can do :


But why do you want to do it like this? From your requirement I think you want that 2nd radio button to be selected by default. For that just use the "checked" attribute. Eg:


Regards


Experience and talent are independent of age
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6



You're changing an attribute, not setting a variable.


GenRocket - Experts at Building Test Data
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Hi Greg + Himanshu,

Thanks for your suggestions. I'll give it a try and let you know how it goes.


What is the difference between these two suggestions?
And also how is it different from the one that I do?

Thanks.
Rajkishore Pujari
Ranch Hand

Joined: Sep 03, 2005
Posts: 46
I think the way you have already coded should work fine as it is, unless some other functionality in your script causing it not to work. There is no difference how you access the radio button using array or id.

You can access a radio object by searching through the elements[] array of the form, or by using document.getElementById().

Here are some links that might help you.

http://www.w3schools.com/htmldom/dom_obj_radio.asp

http://www.w3schools.com/js/tryit.asp?filename=try_dom_radio_checked
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
I try the two suggestions and they don't work either.



Below is my code:
Rajkishore Pujari
Ranch Hand

Joined: Sep 03, 2005
Posts: 46
Hey,

I guess I didn't look at the code keenly before. You were using input type "reset". So according my understanding it resets the page to look like when its loaded. And your onclick function will be executed before it actually does the reset, that means your changes are lost. So either you use input type "button" to get your changes or have the checked="checked" attribute in the input radio for default checked
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You would have to use a setTimeout to cause it to happen after the reset fires. Right now you are clicking it, than the reset action happens, which resets it back.

Eric
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
I would say just 2 things:

1. edit your function as -
and the call as -
<input type="reset" name="resetBtn" id="resetBtn" value="Reset selection"
onclick="return resetSpeedResultTable(this.form);" />
There is another way to do the same thing, first try this.

2. This all can be done by the power of just "1 word" if you tell : "My requirement is to have that radio button selected by default". Do you want that radio to be selected when the page loads? PLEASE do answer this.

Regards
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Himanshu, thanks. I'll try your suggestion.
Regarding this: "My requirement is to have that radio button selected by default", the answer is no.

Eric, how can I use setTimeout()? can you please explain more?

Thanks guys.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

change your js function like this



and change your input type reset to this



Swastik
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
That last post will not reset the form since it is cancelling the click.

Eric, how can I use setTimeout()? can you please explain more?


Did you look up setTimeout in your favorite search engine?

Eric
Susan Smith
Ranch Hand

Joined: Oct 13, 2007
Posts: 224
Swastik, Himanshu: Eric is right, the reset button is cancelled.

I add this one line, looks good now:

Thanks for the help guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Check a checkbox after hitting a reset button