Buy Now
Sign in

Clean field and fdropdown onchange

Pigna , February 12 at 17:54
Answered
P
Pigna
Hi!
I've a form with four dropdown: A, 1, 2 and 3 (1, 2 and 3 are hidden).
When a user make a choice in A, one of the other dropdown becomes visible (ex: 1). When the user make a choice in this dropdown a lot of field (text and dropdown) are shown.
If the user change his choice in 1, the visible fields change.
If the user change his choice in A (ex: 2), every fields return invisible except 2. When the user make a choice in 2, others fields are shown, but some are the same for 1 and 2 (or 2 and 3, or 3 and 1, but not for 1, 2 and 3). So i need to clean every fields when A changes.
In CF5 i've a simple js script to do that, like:
document.getElementById("field_id").value = "";
for every fields. The script worked for the text fields and for the dropdown fields.
In CF6 (every things is the same: name, id, etc.) it works only for the text fields.
I've tried also
document.getElementById("field_id").selectedIndex = "0";
or
document.getElementById("field_id").selectedIndex = 0;
they work perfectly with a not CF form but not in CF.
What am I doing wrong?
There's another way?
Thank you all!​
admin
Hi Pigna,
v6 has a special dropdown effect and this may not work, but you may try this:
$("#field_id").val("value here");
OR
$('#field_id').dropdown('set selected', "value here");
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
P
Pigna
Thank you Max,
i've tried
$("#field_id").val("");
$("#field_id").val(0);
$("#field_id")[0].selectedIndex = 0;
$("#field_id option").eq(0).prop("selected", true);
they all works out CF but not in CF6 (the first works also for the text fields in CF6)​
Sorry but i don't understand what is 'set selected' in your
$('#field_id').dropdown('set selected', "value here");
P
Pigna
Hi Max!
I've got the solution analysing the code with the browser element inspector. I need to use​
$("#field_id").val("");
AND
 $("#field_id ~ div").eq(0).text("");
If I use only the first nothing happens, but if I use only the second the dropdown field becomes empty and not works anymore.
I hope there aren't collateral problems doing this.​
admin
Hi Pigna,
Good news, But I think that its better to try this one:
$('#field_id').dropdown('set selected', "value here");
only the "value here" should be changed to the dropdown value you want to set selected.
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
P
Pigna
I had tried before but probably I had something wrong.
It's work perfectly!
Thank's Max.
P.