Custom form > Select > onchange - display text


(paul walker) #1

Hi Folks
My wish is to use javascript to display the ‘value’ of a select field once the user has has a selection. Is this possible

For the sake of an example please see below;
Value,Text
You have selected “A”,A
You have selected “B”,B
You have selected “C”,C
You have selected “D”,D

My actual form display is set up as below

%question_label_643011_q10% %question_field_643011_q10% %begin_question_error_643011_q10%
%question_error_643011_q10%
%end_question_error_643011_q10%

thank you
pw


(Nic Hubbard) #2

Yes, this is possible. What have you tried so far? Are you proficient in JS?


(paul walker) #3

Hi Nic
Proficient would be rather an overstatement - but I can get my head around it :slight_smile:
Pulled straight from w3schools I am trying to achieve the following

Audi BMW Mercedes Volvo

However, where I am confused is how to apply the ‘onchange’ function to the select field “%question_field_643011_q10%” when using keywords

%question_label_643011_q10% %question_field_643011_q10% %begin_question_error_643011_q10%

%question_error_643011_q10%

%end_question_error_643011_q10%


(paul walker) #4

OOpps, my code was stripped - this is what I am trying to do - https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onchange


#5

There is an ‘Extras’ field for the question that should allow you to provide an onchange event handler.

Otherwise, rather than using the %question_field_% keyword you can write the select html manually (you can copy the %question_field_% output html as a starter)

You can also attach the event handler using javascript:

document.getElementById(“q643011_q10”).onchange = myFunction;


(paul walker) #6

Hi BKelly
Thanks for that - works perfectly
I was able to add the onchange function to the ‘extras’ field and it works perfect - you are my hero for today (Other than David Gilmour)
Cheers man!! :slight_smile: