Page 1 of 1

Get value of selection list by jQuery

Posted: Tue Mar 28, 2023 1:29 am
by bern_a3168

Need help on the client-side script.

the value for this field is character. if I select "1" it supposed to hide the "Nationality_of_spouse" field. the code below did not do the trick. not sure if I missed anything.

{ // keys = event types, values = handler functions
	"change": function(e) {
		// Your code
	if (this.value == '1') {
	    $(this).fields("Nationality_of_spouse").visible(false);
	    $(this).fields("Nationality_of_spouse").value("N/A");
     } else {
         		$(this).fields("Nationality_of_spouse").visible(true);
        } 
	}
}

appreciate if can help.


Re: Client-side script is not working as expected

Posted: Tue Mar 28, 2023 8:35 am
by mobhar

As always, you may press F12 from your browser, and check whether any Javascript error message from Console panel.


Re: My client-side script is not working as expected

Posted: Tue Mar 28, 2023 9:00 am
by arbei

bern_a3168 wrote:

if I select "1"...

If your Edit Tag for the field is SELECT or RADIO (not textbox), you cannot use this.value to get the selected value, you should use $(this).val() or $(this).value().


Re: My client-side script is not working as expected

Posted: Tue Apr 04, 2023 12:45 am
by bern_a3168

Have changed the code as below and it's now working.

	if ($(this).fields("marital_status").value() != '1')
	{
	    $(this).fields("Nationality_of_spouse").visible(true);
     } else {
         		$(this).fields("Nationality_of_spouse").visible(false);
         		$(this).fields("Nationality_of_spouse").value("N/A");
        } 

Thanks!