Page 1 of 1

How to change the text of field description based on dropdown list selection

Posted: 2021-02-25 10:49
by ayussuf
Hello,

I'am trying to change the text of field description in detail view based on the selection of user in dropdown list. I've make some jquery code and put it on tablename-dv.js. Unfortunately it doesn't work.

But if I put the code in console, it work. But if I change another dropdown list, it fail to work again.

What is the problem. Can somebody help?

Thank you

This is the code:

Code: Select all

$j(function () {
    $j('#s2id_bidang-container > a > span').on('DOMSubtreeModified',function(){
        if ($j(this).text() == 'KanBA' || $j(this).text() == 'KanPIPQ') {
            $j('#perancangan-description > div').text('A. KANDUNGAN (ASPEK PERANCANGAN PEMBELAJARAN & PEMUDAHCARAAN, PDPC)');            
         } else if ($j(this).text() == 'PedBA' || $j(this).text() == 'PedPIPQ') {			
	    $j('#perancangan-description > div').text('A. PEDAGOGI (ASPEK PERANCANGAN PEMBELAJARAN & PEMUDAHCARAAN, PDPC)');
	};
    });
});

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-26 22:00
by pbottcher
Hi,

I guess you need to wait for the dropdown to be created first. Usually it is create a little bit later, so your script is executed, but does not find the container and hence does not work. If you try it in debug-mode, the dropdown is already there and it works.
Pls. search the forum as it was already described how to do that.

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-26 23:44
by ayussuf
Thank you for your response.

To achieve this, I've put the code in footer-extras.php. But it still not work.

What I wanna do is to create toggle switch between the first condition and the other condition..

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-27 08:40
by pbottcher
Hi,
even in footer-extras the code is executed too early. You need to either wait for a certain time, or check for the dom element to exist and execute your code afterwards

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-27 11:06
by ayussuf
pböttcher wrote:
2021-02-27 08:40
Hi,
even in footer-extras the code is executed too early. You need to either wait for a certain time, or check for the dom element to exist and execute your code afterwards
How do I make it or check the DOM element?

Sorry for asking this question. I'm very new in this matter.

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-27 11:53
by pbottcher

Re: How to change the text of field description based on dropdown list selection

Posted: 2021-02-27 12:37
by ayussuf
Thank you very much pböttcher