How To Auto Hide Form Entry Based On Multi-choice Radio Button?
I have a form with several radio button questions.
I would like each question to disappear automatically once the radio button is clicked.
Can it be done in Javascript?
Here's the form code:
In this case I would like id="frm_field_682_container" to disappear if either of the radio button options are selected (name="item_meta[683]" id="field_683-0" or name="item_meta[682]" id="field_682-1" value="Option 2").
Yes, it can be done in JS. I would not recommend it, but the following code should do what you want.
I would not recommend it because the OP cannot change their mind if the RBtn is checked on purpose of accidently.
I would recommend at least adding a button that would restore original options at some point.
Before I wasted anyone's time though, I should have clarified that this form is generated by the FormidablePro wordpress plugin.
I don't have the luxury of editing the form by adding onclick functions. (I would lose the backend FormidablePro analytics).
Can it be down using javascript and CSS, using .css('visibility','hidden')? Something like hiding id="frm_field_682_container", with an if/then statement, if input of item_meta[682] does not = "select" then hide css?
...and doing it without altering the form itself?
P.S. I already asked the FormidablePro help desk. It's beyond their scope
I don't use wordpress so I'm not sure what can and cannot be done there.
Unless you can change the form at some time, I think it would be hard to change the actions of the form.
Even changing the css state from visibility to hidden involves some kind of event occuring, in this case a change to the radio button status.
Perhaps some other forum members have come across this problem and can give you the answer you desire.
With WordPress head injection plugins I can inject any code into the <head> tag.
I can add any code to the <body> tag too. PHP can be added too, but with a separate plugin. Javascript is a simpler solution if possible.
I just can't change the form code itself. I need to do it using CSS and Javascript outside the form. I think it can be done using visibility, hidden class with CSS and javascript. Just don't know the specific code.
Here's how they are doing that to show/hid the submit button on the form (I can imagine something like this could be applied here):
Code:
(Change 5 to the ID of your form. Change 25, 26, and 27 to the IDs of your form fields and add the additional fields to check.)
<script type="text/javascript">
jQuery(document).ready(function($){
$("#frm_form_5_container input[type=submit]").attr('disabled','disabled'); //disable submit button by default
$("input[name='item_meta[25]'], input[name='item_meta[26]'], input[name='item_meta[27]']").change(function(){
var submit = true;
if($("input[name='item_meta[25]']:checked").val() == 'No' ||
$("input[name='item_meta[26]']:checked").val() == 'No' ||
$("input[name='item_meta[27]']:checked").val() == 'No')
submit = false;
if(submit){$("#frm_form_5_container input[type=submit]").removeAttr('disabled'); }
else{$("#frm_form_5_container input[type=submit]").attr('disabled','disabled'); }
});
});
</script>
Bookmarks