1

I have a form that has two parts to it. Yes or No.

Yes if you were present (Shows a div)

No if you were absent (Show a div)

What i'm trying to get do is that if the user selects No and selects any input and then decides to go back to Yes i need to reset the value of any item in No back to the form default.

Thank you

My fiddle is below for a visual experience..

http://jsfiddle.net/5nTsk/4/

webb
  • 215
  • 1
  • 5
  • 12
  • 1
    you have duplicate IDs (btnyes)... Related to the question, I would build all the logic of the reset on a function and then call it via the click on the yes. – jackJoe Jul 26 '11 at 23:12

3 Answers3

0

Just use Javascript's reset() method.

Here's an example that will reset the first form of a page (using jQuery's get()):

$('form').get(0).reset();

On Stackoverflow, this is the searchbox (you can try using the console of Firebug/ChromeDevTools).

You can then manually reselect Yes/No if you want to.

middus
  • 9,103
  • 1
  • 31
  • 33
0

In case you want to reset the entire form you can go with middus answer.

Or else if you need to reset a portion of your page then you can use:

$(':input','#mycontainer')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');

This will only reset the input elements that are children of mycontainer. And this should do the trick.

Aleyna
  • 1,857
  • 4
  • 20
  • 27
0

use this simple function:

function defaultNo(){
    $("#getmytimetaken select").val("0").removeAttr('disabled');
}

and place it at the click:

if($(this).val() == "getmytimeregular") defaultNo();

fiddle: http://jsfiddle.net/5nTsk/7/

P.S. of course you don't even need the function, but it could be handy to use it on other situations, like a reset button, etc.

jackJoe
  • 11,078
  • 8
  • 49
  • 64