Ajax / Jquery - Select / mark an option disabled automatically

Asked

Viewed 123 times

1

Fala galera!

The following is, I have a dynamic page where the elements of the selects are loaded via Ajax according to the elements previously selected in other selects, type, for example, when selecting the City in a select and the county combo loads the municipalities of the previously selected city, finally...

Everything is working perfectly, but has a select that it has fixed values, IE, are loaded via Ajax, but the values never change, what changes is the option selected, the option must be selected (have Selected) automatically according to what was selected in previous combos.

This it already does today, but as the combo is not blocked the user has the option to choose another option that is not in accordance with the information passed in the other combos, so I put a jquery code to block this select ($('#iddocampo').prop('disabled', true)), then it gets block, but now it can no longer check/select the correct option when it is blocked.

In short, when the select is unlocked, it marks/selects the right option according to the parameters selected in the other combos/selects, but when this select is locked it cannot check/select the right option, always marked the first option of select.

Does anyone know why this happens? Some light?

I await your help!!!

  • 3

    You can show the code that changes this select?

  • It is possible to change a select even when disabled: https://jsfiddle.net/f9gnryqb/ - can you explain your problem better? if you want to adapt jsFiddle to show your problem

  • Hi Sergio.So it’s a little harder than it looks because the html is all dynamically loaded. The code snippet that loads that specific select is this:

  • Gabriela, put the question I help to format. Click on [Dit]...

  • Gabriela, can you join an example of HTML? or jsFiddle with an example?

  • Yes Sergio, tomorrow I will try to detail better... But what I want is exactly how you posted there, only it can’t be disabled because otherwise it doesn’t enter Submit....

  • You can have so disabled and then have an input[type="Hidden"] that saves the value...

  • I can have a Hidden with the same select id?

  • No. But there are ways to solve this. Viewing HTML makes it easier to give suggestions.

  • The worst thing about Sérgio is that he doesn’t have html. .rs... All the code is generated dynamically.... Do you know OTRS? This is where I’m going...

Show 5 more comments

1 answer

0

Hi, I’ve been through something similar, I think that might be it: Replace the disabled for readonly. I think it works =)

  • Raylan, readonly does not work in select, it does not block the field.

  • Um, worse than it is... is it not possible for you to replace the selects that cannot be changed by inputs? then you would put the readonly and solve. it will continue showing the value and will not be changeable.

  • So you can’t. You have to continue with select. Do you know OTRS? It’s what I’m doing, the fields are created dynamically, it’s very boring to touch it, it’s done in perl, anyway. So I just wanted to leave this fixed select, not giving the user option to change...

  • For unfortunately I have no knowledge =/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.